Documentation TYPO3 par Ameos |
00001 <?php 00002 /* 00003 @version V4.93 10 Oct 2006 (c) 2000-2006 John Lim (jlim#natsoft.com.my). All rights reserved. 00004 Released under both BSD license and Lesser GPL library license. 00005 Whenever there is any discrepancy between the two licenses, 00006 the BSD license will take precedence. 00007 Contribution by Frank M. Kromann <frank@frontbase.com>. 00008 Set tabs to 8. 00009 */ 00010 00011 // security - hide paths 00012 if (!defined('ADODB_DIR')) die(); 00013 00014 if (! defined("_ADODB_FBSQL_LAYER")) { 00015 define("_ADODB_FBSQL_LAYER", 1 ); 00016 00017 class ADODB_fbsql extends ADOConnection { 00018 var $databaseType = 'fbsql'; 00019 var $hasInsertID = true; 00020 var $hasAffectedRows = true; 00021 var $metaTablesSQL = "SHOW TABLES"; 00022 var $metaColumnsSQL = "SHOW COLUMNS FROM %s"; 00023 var $fmtTimeStamp = "'Y-m-d H:i:s'"; 00024 var $hasLimit = false; 00025 00026 function ADODB_fbsql() 00027 { 00028 } 00029 00030 function _insertid() 00031 { 00032 return fbsql_insert_id($this->_connectionID); 00033 } 00034 00035 function _affectedrows() 00036 { 00037 return fbsql_affected_rows($this->_connectionID); 00038 } 00039 00040 function &MetaDatabases() 00041 { 00042 $qid = fbsql_list_dbs($this->_connectionID); 00043 $arr = array(); 00044 $i = 0; 00045 $max = fbsql_num_rows($qid); 00046 while ($i < $max) { 00047 $arr[] = fbsql_tablename($qid,$i); 00048 $i += 1; 00049 } 00050 return $arr; 00051 } 00052 00053 // returns concatenated string 00054 function Concat() 00055 { 00056 $s = ""; 00057 $arr = func_get_args(); 00058 $first = true; 00059 00060 $s = implode(',',$arr); 00061 if (sizeof($arr) > 0) return "CONCAT($s)"; 00062 else return ''; 00063 } 00064 00065 // returns true or false 00066 function _connect($argHostname, $argUsername, $argPassword, $argDatabasename) 00067 { 00068 $this->_connectionID = fbsql_connect($argHostname,$argUsername,$argPassword); 00069 if ($this->_connectionID === false) return false; 00070 if ($argDatabasename) return $this->SelectDB($argDatabasename); 00071 return true; 00072 } 00073 00074 // returns true or false 00075 function _pconnect($argHostname, $argUsername, $argPassword, $argDatabasename) 00076 { 00077 $this->_connectionID = fbsql_pconnect($argHostname,$argUsername,$argPassword); 00078 if ($this->_connectionID === false) return false; 00079 if ($argDatabasename) return $this->SelectDB($argDatabasename); 00080 return true; 00081 } 00082 00083 function &MetaColumns($table) 00084 { 00085 if ($this->metaColumnsSQL) { 00086 00087 $rs = $this->Execute(sprintf($this->metaColumnsSQL,$table)); 00088 00089 if ($rs === false) return false; 00090 00091 $retarr = array(); 00092 while (!$rs->EOF){ 00093 $fld = new ADOFieldObject(); 00094 $fld->name = $rs->fields[0]; 00095 $fld->type = $rs->fields[1]; 00096 00097 // split type into type(length): 00098 if (preg_match("/^(.+)\((\d+)\)$/", $fld->type, $query_array)) { 00099 $fld->type = $query_array[1]; 00100 $fld->max_length = $query_array[2]; 00101 } else { 00102 $fld->max_length = -1; 00103 } 00104 $fld->not_null = ($rs->fields[2] != 'YES'); 00105 $fld->primary_key = ($rs->fields[3] == 'PRI'); 00106 $fld->auto_increment = (strpos($rs->fields[5], 'auto_increment') !== false); 00107 $fld->binary = (strpos($fld->type,'blob') !== false); 00108 00109 $retarr[strtoupper($fld->name)] = $fld; 00110 $rs->MoveNext(); 00111 } 00112 $rs->Close(); 00113 return $retarr; 00114 } 00115 return false; 00116 } 00117 00118 // returns true or false 00119 function SelectDB($dbName) 00120 { 00121 $this->database = $dbName; 00122 if ($this->_connectionID) { 00123 return @fbsql_select_db($dbName,$this->_connectionID); 00124 } 00125 else return false; 00126 } 00127 00128 00129 // returns queryID or false 00130 function _query($sql,$inputarr) 00131 { 00132 return fbsql_query("$sql;",$this->_connectionID); 00133 } 00134 00135 /* Returns: the last error message from previous database operation */ 00136 function ErrorMsg() 00137 { 00138 $this->_errorMsg = @fbsql_error($this->_connectionID); 00139 return $this->_errorMsg; 00140 } 00141 00142 /* Returns: the last error number from previous database operation */ 00143 function ErrorNo() 00144 { 00145 return @fbsql_errno($this->_connectionID); 00146 } 00147 00148 // returns true or false 00149 function _close() 00150 { 00151 return @fbsql_close($this->_connectionID); 00152 } 00153 00154 } 00155 00156 /*-------------------------------------------------------------------------------------- 00157 Class Name: Recordset 00158 --------------------------------------------------------------------------------------*/ 00159 00160 class ADORecordSet_fbsql extends ADORecordSet{ 00161 00162 var $databaseType = "fbsql"; 00163 var $canSeek = true; 00164 00165 function ADORecordSet_fbsql($queryID,$mode=false) 00166 { 00167 if (!$mode) { 00168 global $ADODB_FETCH_MODE; 00169 $mode = $ADODB_FETCH_MODE; 00170 } 00171 switch ($mode) { 00172 case ADODB_FETCH_NUM: $this->fetchMode = FBSQL_NUM; break; 00173 case ADODB_FETCH_ASSOC: $this->fetchMode = FBSQL_ASSOC; break; 00174 case ADODB_FETCH_BOTH: 00175 default: 00176 $this->fetchMode = FBSQL_BOTH; break; 00177 } 00178 return $this->ADORecordSet($queryID); 00179 } 00180 00181 function _initrs() 00182 { 00183 GLOBAL $ADODB_COUNTRECS; 00184 $this->_numOfRows = ($ADODB_COUNTRECS) ? @fbsql_num_rows($this->_queryID):-1; 00185 $this->_numOfFields = @fbsql_num_fields($this->_queryID); 00186 } 00187 00188 00189 00190 function &FetchField($fieldOffset = -1) { 00191 if ($fieldOffset != -1) { 00192 $o = @fbsql_fetch_field($this->_queryID, $fieldOffset); 00193 //$o->max_length = -1; // fbsql returns the max length less spaces -- so it is unrealiable 00194 $f = @fbsql_field_flags($this->_queryID,$fieldOffset); 00195 $o->binary = (strpos($f,'binary')!== false); 00196 } 00197 else if ($fieldOffset == -1) { /* The $fieldOffset argument is not provided thus its -1 */ 00198 $o = @fbsql_fetch_field($this->_queryID);// fbsql returns the max length less spaces -- so it is unrealiable 00199 //$o->max_length = -1; 00200 } 00201 00202 return $o; 00203 } 00204 00205 function _seek($row) 00206 { 00207 return @fbsql_data_seek($this->_queryID,$row); 00208 } 00209 00210 function _fetch($ignore_fields=false) 00211 { 00212 $this->fields = @fbsql_fetch_array($this->_queryID,$this->fetchMode); 00213 return ($this->fields == true); 00214 } 00215 00216 function _close() { 00217 return @fbsql_free_result($this->_queryID); 00218 } 00219 00220 function MetaType($t,$len=-1,$fieldobj=false) 00221 { 00222 if (is_object($t)) { 00223 $fieldobj = $t; 00224 $t = $fieldobj->type; 00225 $len = $fieldobj->max_length; 00226 } 00227 $len = -1; // fbsql max_length is not accurate 00228 switch (strtoupper($t)) { 00229 case 'CHARACTER': 00230 case 'CHARACTER VARYING': 00231 case 'BLOB': 00232 case 'CLOB': 00233 case 'BIT': 00234 case 'BIT VARYING': 00235 if ($len <= $this->blobSize) return 'C'; 00236 00237 // so we have to check whether binary... 00238 case 'IMAGE': 00239 case 'LONGBLOB': 00240 case 'BLOB': 00241 case 'MEDIUMBLOB': 00242 return !empty($fieldobj->binary) ? 'B' : 'X'; 00243 00244 case 'DATE': return 'D'; 00245 00246 case 'TIME': 00247 case 'TIME WITH TIME ZONE': 00248 case 'TIMESTAMP': 00249 case 'TIMESTAMP WITH TIME ZONE': return 'T'; 00250 00251 case 'PRIMARY_KEY': 00252 return 'R'; 00253 case 'INTEGER': 00254 case 'SMALLINT': 00255 case 'BOOLEAN': 00256 00257 if (!empty($fieldobj->primary_key)) return 'R'; 00258 else return 'I'; 00259 00260 default: return 'N'; 00261 } 00262 } 00263 00264 } //class 00265 } // defined 00266 ?>