3 version V4.20 22 Feb 2004 (c) 2000-2004 John Lim (jlim@natsoft.com.my). All rights
5 Released under both BSD license and Lesser GPL library license.
6 Whenever there is any discrepancy between the two licenses,
7 the BSD license will take precedence.
8 Set tabs to 4 for best viewing.
10 Latest version is available at http://php.weblogs.com/
12 21.02.2002 - Wade Johnson wade@wadejohnson.de
13 Extended ODBC class for Sybase SQLAnywhere.
14 1) Added support to retrieve the last row insert ID on tables with
15 primary key column using autoincrement function.
17 2) Added blob support. Usage:
18 a) create blob variable on db server:
20 $dbconn->create_blobvar($blobVarName);
22 b) load blob var from file. $filename must be complete path
24 $dbcon->load_blobvar_from_file($blobVarName, $filename);
26 c) Use the $blobVarName in SQL insert or update statement in the values
29 $recordSet = $dbconn->Execute('INSERT INTO tabname (idcol, blobcol) '
31 'VALUES (\'test\', ' . $blobVarName . ')');
33 instead of loading blob from a file, you can also load from
34 an unformatted (raw) blob variable:
35 $dbcon->load_blobvar_from_var($blobVarName, $varName);
37 d) drop blob variable on db server to free up resources:
38 $dbconn->drop_blobvar($blobVarName);
40 Sybase_SQLAnywhere data driver. Requires ODBC.
44 if (!defined('_ADODB_ODBC_LAYER')) {
45 include(ADODB_DIR
."/drivers/adodb-odbc.inc.php");
48 if (!defined('ADODB_SYBASE_SQLANYWHERE')){
50 define('ADODB_SYBASE_SQLANYWHERE',1);
52 class ADODB_sqlanywhere
extends ADODB_odbc
{
53 var $databaseType = "sqlanywhere";
54 var $hasInsertID = true;
56 function ADODB_sqlanywhere()
61 function _insertid() {
62 return $this->GetOne('select @@identity');
65 function create_blobvar($blobVarName) {
66 $this->Execute("create variable $blobVarName long binary");
70 function drop_blobvar($blobVarName) {
71 $this->Execute("drop variable $blobVarName");
75 function load_blobvar_from_file($blobVarName, $filename) {
78 $fd = fopen ($filename, "rb");
80 $integer_chunks = (integer)filesize($filename) / $chunk_size;
81 $modulus = filesize($filename) %
$chunk_size;
86 for($loop=1;$loop<=$integer_chunks;$loop++
){
87 $contents = fread ($fd, $chunk_size);
88 $contents = bin2hex($contents);
92 for($loop2=0;$loop2<strlen($contents);$loop2+
=2){
93 $hexstring .= '\x' . substr($contents,$loop2,2);
96 $hexstring = $this->qstr($hexstring);
98 $this->Execute("set $blobVarName = $blobVarName || " . $hexstring);
105 function load_blobvar_from_var($blobVarName, &$varName) {
108 $integer_chunks = (integer)strlen($varName) / $chunk_size;
109 $modulus = strlen($varName) %
$chunk_size;
111 $integer_chunks +
= 1;
114 for($loop=1;$loop<=$integer_chunks;$loop++
){
115 $contents = substr ($varName, (($loop - 1) * $chunk_size), $chunk_size);
116 $contents = bin2hex($contents);
120 for($loop2=0;$loop2<strlen($contents);$loop2+
=2){
121 $hexstring .= '\x' . substr($contents,$loop2,2);
124 $hexstring = $this->qstr($hexstring);
126 $this->Execute("set $blobVarName = $blobVarName || " . $hexstring);
133 Insert a null into the blob field of the table first.
134 Then use UpdateBlob to store the blob.
138 $conn->Execute('INSERT INTO blobtable (id, blobcol) VALUES (1, null)');
139 $conn->UpdateBlob('blobtable','blobcol',$blob,'id=1');
141 function UpdateBlob($table,$column,&$val,$where,$blobtype='BLOB')
143 $blobVarName = 'hold_blob';
144 $this->create_blobvar($blobVarName);
145 $this->load_blobvar_from_var($blobVarName, $val);
146 $this->Execute("UPDATE $table SET $column=$blobVarName WHERE $where");
147 $this->drop_blobvar($blobVarName);
152 class ADORecordSet_sqlanywhere
extends ADORecordSet_odbc
{
154 var $databaseType = "sqlanywhere";
156 function ADORecordSet_sqlanywhere($id,$mode=false)
158 $this->ADORecordSet_odbc($id,$mode);