Source for file adodb-sybase.inc.php
Documentation is available at adodb-sybase.inc.php
V4.97 22 Jan 2008 (c) 2000-2008 John Lim. All rights reserved.
Released under both BSD license and Lesser GPL library license.
Whenever there is any discrepancy between the two licenses,
the BSD license will take precedence.
Set tabs to 4 for best viewing.
Latest version is available at http://adodb.sourceforge.net
Sybase driver contributed by Toni (toni.tunkkari@finebyte.com)
- MSSQL date patch applied.
Date patch by Toni 15 Feb 2002
var $metaTablesSQL= "select name from sysobjects where type='U' or type='V'";
// see http://sybooks.sybase.com/onlinebooks/group-aw/awg0800e/dbrfen8/@ebt-link;pt=5981;uf=0?target=0;window=new;showtoc=true;book=dbrfen8
var $metaColumnsSQL = "SELECT c.column_name, c.column_type, c.width FROM syscolumn c, systable t WHERE t.table_name='%s' AND c.table_id=t.table_id AND t.table_type='BASE'";
"select c.name,t.name,c.length from
syscolumns c join systypes t on t.xusertype=c.xusertype join sysobjects o on o.id=c.id
// might require begintrans -- committrans
return $this->GetOne('select @@identity');
// might require begintrans -- committrans
return $this->GetOne('select @@rowcount');
// http://www.isug.com/Sybase_FAQ/ASE/section6.1.html#6.1.4
function RowLock($tables,$where,$flds= 'top 1 null as ignore')
return $this->GetOne("select $flds from $tables HOLDLOCK where $where");
$this->databaseName = $dbName; # obsolete, retained for compat with older adodb versions
return @sybase_select_db($dbName);
/* Returns: the last error message from previous database operation
Note: This function is NOT available for Microsoft SQL Server. */
$this->_errorMsg = sybase_get_last_message();
$this->_errorMsg = isset ($php_errormsg) ? $php_errormsg : 'SYBASE error messages not supported on this platform';
function _connect($argHostname, $argUsername, $argPassword, $argDatabasename)
$this->_connectionID = sybase_connect($argHostname,$argUsername,$argPassword);
if ($argDatabasename) return $this->SelectDB($argDatabasename);
function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename)
$this->_connectionID = sybase_pconnect($argHostname,$argUsername,$argPassword);
if ($argDatabasename) return $this->SelectDB($argDatabasename);
// returns query ID if successful, otherwise false
function _query($sql,$inputarr)
// See http://www.isug.com/Sybase_FAQ/ASE/section6.2.html#6.2.12
function &SelectLimit($sql,$nrows=- 1,$offset=- 1,$inputarr= false,$secs2cache= 0)
if ($secs2cache > 0) {// we do not cache rowcount, so we have to load entire recordset
$nrows = (integer) $nrows;
$offset = (integer) $offset;
$cnt = ($nrows >= 0) ? $nrows : 999999999;
if ($offset > 0 && $cnt) $cnt += $offset;
$this->Execute("set rowcount $cnt");
# Added 2003-10-05 by Chris Phillipson
# Used ASA SQL Reference Manual -- http://sybooks.sybase.com/onlinebooks/group-aw/awg0800e/dbrfen8/@ebt-link;pt=16756?target=%25N%15_12018_START_RESTART_N%25
# to convert similar Microsoft SQL*Server (mssql) API into Sybase compatible version
// Format date column in sql string given an input format that understands Y M D
for ($i= 0; $i < $len; $i++ ) {
$s .= "datename(yy,$col)";
$s .= "convert(char(3),$col,0)";
$s .= "replace(str(month($col),2),' ','0')";
$s .= "datename(qq,$col)";
$s .= "replace(str(datepart(dd,$col),2),' ','0')";
$s .= "substring(convert(char(14),$col,0),13,2)";
$s .= "replace(str(datepart(hh,$col),2),' ','0')";
$s .= "replace(str(datepart(mi,$col),2),' ','0')";
$s .= "replace(str(datepart(ss,$col),2),' ','0')";
$s .= "substring(convert(char(19),$col,0),18,2)";
# Added 2003-10-07 by Chris Phillipson
# Used ASA SQL Reference Manual -- http://sybooks.sybase.com/onlinebooks/group-aw/awg0800e/dbrfen8/@ebt-link;pt=5981;uf=0?target=0;window=new;showtoc=true;book=dbrfen8
# to convert similar Microsoft SQL*Server (mssql) API into Sybase compatible version
$sql = "SELECT c.column_name " .
"FROM syscolumn c, systable t " .
"WHERE t.table_name='$table' AND c.table_id=t.table_id " .
"AND t.table_type='BASE' " .
if ($a && sizeof($a)> 0) return $a;
/*--------------------------------------------------------------------------------------
--------------------------------------------------------------------------------------*/
global $ADODB_sybase_mths;
$ADODB_sybase_mths = array(
'JAN'=> 1,'FEB'=> 2,'MAR'=> 3,'APR'=> 4,'MAY'=> 5,'JUN'=> 6,
'JUL'=> 7,'AUG'=> 8,'SEP'=> 9,'OCT'=> 10,'NOV'=> 11,'DEC'=> 12);
// _mths works only in non-localised system
var $_mths = array('JAN'=> 1,'FEB'=> 2,'MAR'=> 3,'APR'=> 4,'MAY'=> 5,'JUN'=> 6,'JUL'=> 7,'AUG'=> 8,'SEP'=> 9,'OCT'=> 10,'NOV'=> 11,'DEC'=> 12);
global $ADODB_FETCH_MODE;
$mode = $ADODB_FETCH_MODE;
/* Returns: an object containing field information.
Get column information in the Recordset object. fetchField() can be used in order to obtain information about
fields in a certain query result. If the field offset isn't specified, the next field that wasn't yet retrieved by
fetchField() is retrieved. */
if ($fieldOffset != - 1) {
$o = @sybase_fetch_field($this->_queryID, $fieldOffset);
else if ($fieldOffset == - 1) { /* The $fieldOffset argument is not provided thus its -1 */
$o = @sybase_fetch_field($this->_queryID);
// older versions of PHP did not support type, only numeric
if ($o && !isset ($o->type)) $o->type = ($o->numeric) ? 'float' : 'varchar';
return @sybase_data_seek($this->_queryID, $row);
function _fetch($ignore_fields= false)
/* close() only needs to be called if you are worried about using too much memory while your script
is running. All associated result memory for the specified result identifier will automatically be freed. */
return @sybase_free_result($this->_queryID);
// sybase/mssql uses a default date like Dec 30 2000 12:00AM
// sybase/mssql uses a default date like Dec 30 2000 12:00AM
global $ADODB_sybase_mths;
if (!ereg( "([A-Za-z]{3})[-/\. ]+([0-9]{1,2})[-/\. ]+([0-9]{4})"
,$v, $rr)) return parent::UnixDate($v);
$themth = $ADODB_sybase_mths[$themth];
if ($themth <= 0) return false;
return mktime(0,0,0,$themth,$rr[2],$rr[3]);
global $ADODB_sybase_mths;
//11.02.2001 Toni Tunkkari toni.tunkkari@finebyte.com
//Changed [0-9] to [0-9 ] in day conversion
if (!ereg( "([A-Za-z]{3})[-/\. ]([0-9 ]{1,2})[-/\. ]([0-9]{4}) +([0-9]{1,2}):([0-9]{1,2}) *([apAP]{0,1})"
,$v, $rr)) return parent::UnixTimeStamp($v);
$themth = $ADODB_sybase_mths[$themth];
if ($themth <= 0) return false;
if ($rr[4]< 12) $rr[4] += 12;
if ($rr[4]== 12) $rr[4] = 0;
return mktime($rr[4],$rr[5],0,$themth,$rr[2],$rr[3]);
|