

Public Member Functions | |
| DB_dbase () | |
| connect ($dsn, $persistent=false) | |
| disconnect () | |
| & | query ($query=null) |
| fetchInto ($result, &$arr, $fetchmode, $rownum=null) | |
| numCols ($foo) | |
| numRows ($foo) | |
| quoteSmart ($in) | |
| tableInfo ($result=null, $mode=null) | |
| __sleep () | |
| __wakeup () | |
| __toString () | |
| toString () | |
| quoteString ($string) | |
| quote ($string=null) | |
| quoteIdentifier ($str) | |
| escapeSimple ($str) | |
| provides ($feature) | |
| setFetchMode ($fetchmode, $object_class= 'stdClass') | |
| setOption ($option, $value) | |
| getOption ($option) | |
| prepare ($query) | |
| autoPrepare ($table, $table_fields, $mode=DB_AUTOQUERY_INSERT, $where=false) | |
| autoExecute ($table, $fields_values, $mode=DB_AUTOQUERY_INSERT, $where=false) | |
| buildManipSQL ($table, $table_fields, $mode, $where=false) | |
| & | execute ($stmt, $data=array()) |
| executeEmulateQuery ($stmt, $data=array()) | |
| executeMultiple ($stmt, $data) | |
| freePrepared ($stmt, $free_resource=true) | |
| modifyQuery ($query) | |
| modifyLimitQuery ($query, $from, $count, $params=array()) | |
| & | query ($query, $params=array()) |
| & | limitQuery ($query, $from, $count, $params=array()) |
| & | getOne ($query, $params=array()) |
| & | getRow ($query, $params=array(), $fetchmode=DB_FETCHMODE_DEFAULT) |
| & | getCol ($query, $col=0, $params=array()) |
| & | getAssoc ($query, $force_array=false, $params=array(), $fetchmode=DB_FETCHMODE_DEFAULT, $group=false) |
| & | getAll ($query, $params=array(), $fetchmode=DB_FETCHMODE_DEFAULT) |
| autoCommit ($onoff=false) | |
| commit () | |
| rollback () | |
| affectedRows () | |
| getSequenceName ($sqn) | |
| nextId ($seq_name, $ondemand=true) | |
| createSequence ($seq_name) | |
| dropSequence ($seq_name) | |
| & | raiseError ($code=DB_ERROR, $mode=null, $options=null, $userinfo=null, $nativecode=null) |
| raiseError ($message=null, $code=null, $mode=null, $options=null, $userinfo=null, $error_class=null, $skipmsg=false) | |
| errorNative () | |
| errorCode ($nativecode) | |
| errorMessage ($dbcode) | |
| getTables () | |
| getListOf ($type) | |
| getSpecialQuery ($type) | |
| _rtrimArrayValues (&$array) | |
| _convertNullArrayValuesToEmpty (&$array) | |
| _PEAR () | |
| & | getStaticProperty ($class, $var) |
| registerShutdownFunc ($func, $args=array()) | |
| isError ($data, $code=null) | |
| setErrorHandling ($mode=null, $options=null) | |
| expectError ($code= '*') | |
| popExpect () | |
| _checkDelExpect ($error_code) | |
| delExpect ($error_code) | |
| throwError ($message=null, $code=null, $userinfo=null) | |
| staticPushErrorHandling ($mode, $options=null) | |
| staticPopErrorHandling () | |
| pushErrorHandling ($mode, $options=null) | |
| popErrorHandling () | |
| loadExtension ($ext) | |
Public Attributes | |
| $phptype = 'dbase' | |
| $dbsyntax = 'dbase' | |
| $features | |
| $errorcode_map | |
| $connection | |
| $dsn = array() | |
| $res_row = array() | |
| $result = 0 | |
| $types | |
| $fetchmode = DB_FETCHMODE_ORDERED | |
| $fetchmode_object_class = 'stdClass' | |
| $was_connected = null | |
| $last_query = '' | |
| $options | |
| $last_parameters = array() | |
| $prepare_tokens = array() | |
| $prepare_types = array() | |
| $prepared_queries = array() | |
| $_debug = false | |
| $_default_error_mode = null | |
| $_default_error_options = null | |
| $_default_error_handler = '' | |
| $_error_class = 'PEAR_Error' | |
| $_expected_errors = array() | |
Definition at line 47 of file dbase.php.
|
|
This constructor calls
Definition at line 147 of file dbase.php. References DB_common::DB_common(). 00148 { 00149 $this->DB_common(); 00150 }
|
|
|
Automatically indicates which properties should be saved when PHP's serialize() function is called
Definition at line 147 of file common.php. 00148 { 00149 if ($this->connection) { 00150 // Don't disconnect(), people use serialize() for many reasons 00151 $this->was_connected = true; 00152 } else { 00153 $this->was_connected = false; 00154 } 00155 if (isset($this->autocommit)) { 00156 return array('autocommit', 00157 'dbsyntax', 00158 'dsn', 00159 'features', 00160 'fetchmode', 00161 'fetchmode_object_class', 00162 'options', 00163 'was_connected', 00164 ); 00165 } else { 00166 return array('dbsyntax', 00167 'dsn', 00168 'features', 00169 'fetchmode', 00170 'fetchmode_object_class', 00171 'options', 00172 'was_connected', 00173 ); 00174 } 00175 }
|
|
|
Automatic string conversion for PHP 5
Definition at line 206 of file common.php. References $info. Referenced by DB_common::toString(). 00207 { 00208 $info = strtolower(get_class($this)); 00209 $info .= ': (phptype=' . $this->phptype . 00210 ', dbsyntax=' . $this->dbsyntax . 00211 ')'; 00212 if ($this->connection) { 00213 $info .= ' [connected]'; 00214 } 00215 return $info; 00216 }
|
|
|
Automatically reconnects to the database when PHP's unserialize() function is called The reconnection attempt is only performed if the object was connected at the time PHP's serialize() function was run.
Definition at line 189 of file common.php. 00190 { 00191 if ($this->was_connected) { 00192 $this->connect($this->dsn, $this->options); 00193 } 00194 }
|
|
|
This method checks unsets an error code if available
Definition at line 396 of file PEAR.php. 00397 { 00398 $deleted = false; 00399 00400 foreach ($this->_expected_errors AS $key => $error_array) { 00401 if (in_array($error_code, $error_array)) { 00402 unset($this->_expected_errors[$key][array_search($error_code, $error_array)]); 00403 $deleted = true; 00404 } 00405 00406 // clean up empty arrays 00407 if (0 == count($this->_expected_errors[$key])) { 00408 unset($this->_expected_errors[$key]); 00409 } 00410 } 00411 return $deleted; 00412 }
|
|
|
Converts all null values in an array to empty strings
Definition at line 2138 of file common.php. Referenced by DB_sybase::fetchInto(), DB_sqlite::fetchInto(), DB_odbc::fetchInto(), DB_oci8::fetchInto(), DB_mysqli::fetchInto(), DB_mysql::fetchInto(), DB_mssql::fetchInto(), DB_msql::fetchInto(), DB_ifx::fetchInto(), DB_fbsql::fetchInto(), and fetchInto(). 02139 { 02140 foreach ($array as $key => $value) { 02141 if (is_null($value)) { 02142 $array[$key] = ''; 02143 } 02144 } 02145 }
|
|
|
Destructor (the emulated type of...). Does nothing right now, but is included for forward compatibility, so subclass destructors should always call it. See the note in the class desciption about output from destructors. public
Definition at line 192 of file PEAR.php. 00192 { 00193 if ($this->_debug) { 00194 printf("PEAR destructor called, class=%s\n", strtolower(get_class($this))); 00195 } 00196 }
|
|
|
Right-trims all strings in an array
Definition at line 2117 of file common.php. Referenced by DB_sybase::fetchInto(), DB_sqlite::fetchInto(), DB_odbc::fetchInto(), DB_oci8::fetchInto(), DB_mysqli::fetchInto(), DB_mysql::fetchInto(), DB_mssql::fetchInto(), DB_msql::fetchInto(), DB_ifx::fetchInto(), DB_fbsql::fetchInto(), and fetchInto(). 02118 { 02119 foreach ($array as $key => $value) { 02120 if (is_string($value)) { 02121 $array[$key] = rtrim($value); 02122 } 02123 } 02124 }
|
|
|
Determines the number of rows affected by a data maniuplation query 0 is returned for queries that don't manipulate data.
Reimplemented in DB_fbsql, DB_ibase, DB_ifx, DB_msql, DB_mssql, DB_mysql, DB_mysqli, DB_oci8, DB_odbc, DB_pgsql, DB_sqlite, and DB_sybase. Definition at line 1703 of file common.php. References DB_common::raiseError(). 01704 { 01705 return $this->raiseError(DB_ERROR_NOT_CAPABLE); 01706 }
|
|
|
Enables or disables automatic commits
Reimplemented in DB_fbsql, DB_ibase, DB_ifx, DB_mssql, DB_mysql, DB_mysqli, DB_oci8, DB_odbc, DB_pgsql, and DB_sybase. Definition at line 1647 of file common.php. References DB_common::raiseError(). 01648 { 01649 return $this->raiseError(DB_ERROR_NOT_CAPABLE); 01650 }
|
|
||||||||||||||||||||
|
Automaticaly generates an insert or update query and call prepare() and execute() with it
Definition at line 832 of file common.php. References DB_common::autoPrepare(), DB_common::execute(), DB_common::freePrepared(), and DB::isError(). 00834 { 00835 $sth = $this->autoPrepare($table, array_keys($fields_values), $mode, 00836 $where); 00837 if (DB::isError($sth)) { 00838 return $sth; 00839 } 00840 $ret =& $this->execute($sth, array_values($fields_values)); 00841 $this->freePrepared($sth); 00842 return $ret; 00843 00844 }
|
|
||||||||||||||||||||
|
Automaticaly generates an insert or update query and pass it to prepare()
Definition at line 800 of file common.php. References $query, DB_common::buildManipSQL(), DB::isError(), DB_common::prepare(), and DB_common::query(). Referenced by DB_common::autoExecute(). 00802 { 00803 $query = $this->buildManipSQL($table, $table_fields, $mode, $where); 00804 if (DB::isError($query)) { 00805 return $query; 00806 } 00807 return $this->prepare($query); 00808 }
|
|
||||||||||||||||||||
|
Produces an SQL query string for autoPrepare() Example:
buildManipSQL('table_sql', array('field1', 'field2', 'field3'),
DB_AUTOQUERY_INSERT);
That returns <samp> INSERT INTO table_sql (field1,field2,field3) VALUES (?,?,?) </samp> NOTES:
Definition at line 879 of file common.php. References $set, $sql, $value, $values, and DB_common::raiseError(). Referenced by DB_common::autoPrepare(). 00880 { 00881 if (count($table_fields) == 0) { 00882 return $this->raiseError(DB_ERROR_NEED_MORE_DATA); 00883 } 00884 $first = true; 00885 switch ($mode) { 00886 case DB_AUTOQUERY_INSERT: 00887 $values = ''; 00888 $names = ''; 00889 foreach ($table_fields as $value) { 00890 if ($first) { 00891 $first = false; 00892 } else { 00893 $names .= ','; 00894 $values .= ','; 00895 } 00896 $names .= $value; 00897 $values .= '?'; 00898 } 00899 return "INSERT INTO $table ($names) VALUES ($values)"; 00900 case DB_AUTOQUERY_UPDATE: 00901 $set = ''; 00902 foreach ($table_fields as $value) { 00903 if ($first) { 00904 $first = false; 00905 } else { 00906 $set .= ','; 00907 } 00908 $set .= "$value = ?"; 00909 } 00910 $sql = "UPDATE $table SET $set"; 00911 if ($where) { 00912 $sql .= " WHERE $where"; 00913 } 00914 return $sql; 00915 default: 00916 return $this->raiseError(DB_ERROR_SYNTAX); 00917 } 00918 }
|
|
|
Commits the current transaction
Reimplemented in DB_fbsql, DB_ibase, DB_ifx, DB_mssql, DB_mysql, DB_mysqli, DB_oci8, DB_odbc, DB_pgsql, and DB_sybase. Definition at line 1660 of file common.php. References DB_common::raiseError(). 01661 { 01662 return $this->raiseError(DB_ERROR_NOT_CAPABLE); 01663 }
|
|
||||||||||||
|
Connect to the database and create it if it doesn't exist Don't call this method directly. Use DB::connect() instead. PEAR DB's dbase driver supports the following extra DSN options: + mode An integer specifying the read/write mode to use (0 = read only, 1 = write only, 2 = read/write). Available since PEAR DB 1.7.0. + fields An array of arrays that PHP's dbase_create() function needs to create a new database. This information is used if the dBase file specified in the "database" segment of the DSN does not exist. For more info, see the PHP manual's dbase_create() page. Available since PEAR DB 1.7.0.
Example of how to connect and establish a new dBase file if necessary:
Definition at line 202 of file dbase.php. References $dsn, PEAR::loadExtension(), and DB_common::raiseError(). 00203 { 00204 if (!PEAR::loadExtension('dbase')) { 00205 return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND); 00206 } 00207 00208 $this->dsn = $dsn; 00209 if ($dsn['dbsyntax']) { 00210 $this->dbsyntax = $dsn['dbsyntax']; 00211 } 00212 00213 /* 00214 * Turn track_errors on for entire script since $php_errormsg 00215 * is the only way to find errors from the dbase extension. 00216 */ 00217 ini_set('track_errors', 1); 00218 $php_errormsg = ''; 00219 00220 if (!file_exists($dsn['database'])) { 00221 $this->dsn['mode'] = 2; 00222 if (empty($dsn['fields']) || !is_array($dsn['fields'])) { 00223 return $this->raiseError(DB_ERROR_CONNECT_FAILED, 00224 null, null, null, 00225 'the dbase file does not exist and ' 00226 . 'it could not be created because ' 00227 . 'the "fields" element of the DSN ' 00228 . 'is not properly set'); 00229 } 00230 $this->connection = @dbase_create($dsn['database'], 00231 $dsn['fields']); 00232 if (!$this->connection) { 00233 return $this->raiseError(DB_ERROR_CONNECT_FAILED, 00234 null, null, null, 00235 'the dbase file does not exist and ' 00236 . 'the attempt to create it failed: ' 00237 . $php_errormsg); 00238 } 00239 } else { 00240 if (!isset($this->dsn['mode'])) { 00241 $this->dsn['mode'] = 0; 00242 } 00243 $this->connection = @dbase_open($dsn['database'], 00244 $this->dsn['mode']); 00245 if (!$this->connection) { 00246 return $this->raiseError(DB_ERROR_CONNECT_FAILED, 00247 null, null, null, 00248 $php_errormsg); 00249 } 00250 } 00251 return DB_OK; 00252 }
|
|
|
Creates a new sequence The name of a given sequence is determined by passing the string provided in the $seq_name argument through PHP's sprintf() function using the value from the seqname_format option as the sprintf()'s format argument. seqname_format is set via setOption().
Reimplemented in DB_fbsql, DB_ibase, DB_msql, DB_mssql, DB_mysql, DB_mysqli, DB_oci8, DB_odbc, DB_pgsql, DB_sqlite, and DB_sybase. Definition at line 1772 of file common.php. References DB_common::raiseError(). 01773 { 01774 return $this->raiseError(DB_ERROR_NOT_CAPABLE); 01775 }
|
|
|
This method deletes all occurences of the specified element from the expected error codes stack.
Definition at line 426 of file PEAR.php. References PEAR::raiseError(). 00427 { 00428 $deleted = false; 00429 00430 if ((is_array($error_code) && (0 != count($error_code)))) { 00431 // $error_code is a non-empty array here; 00432 // we walk through it trying to unset all 00433 // values 00434 foreach($error_code as $key => $error) { 00435 if ($this->_checkDelExpect($error)) { 00436 $deleted = true; 00437 } else { 00438 $deleted = false; 00439 } 00440 } 00441 return $deleted ? true : PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME 00442 } elseif (!empty($error_code)) { 00443 // $error_code comes alone, trying to unset it 00444 if ($this->_checkDelExpect($error_code)) { 00445 return true; 00446 } else { 00447 return PEAR::raiseError("The expected error you submitted does not exist"); // IMPROVE ME 00448 } 00449 } else { 00450 // $error_code is empty 00451 return PEAR::raiseError("The expected error you submitted is empty"); // IMPROVE ME 00452 } 00453 }
|
|
|
Disconnects from the database server
Definition at line 262 of file dbase.php. 00263 { 00264 $ret = @dbase_close($this->connection); 00265 $this->connection = null; 00266 return $ret; 00267 }
|
|
|
Deletes a sequence
Reimplemented in DB_fbsql, DB_ibase, DB_msql, DB_mssql, DB_mysql, DB_mysqli, DB_oci8, DB_odbc, DB_pgsql, DB_sqlite, and DB_sybase. Definition at line 1790 of file common.php. References DB_common::raiseError(). 01791 { 01792 return $this->raiseError(DB_ERROR_NOT_CAPABLE); 01793 }
|
|
|
Maps native error codes to DB's portable ones Uses the $errorcode_map property defined in each driver.
Reimplemented in DB_ibase, DB_ifx, DB_msql, DB_pgsql, DB_sqlite, and DB_sybase. Definition at line 1880 of file common.php. Referenced by DB_fbsql::fbsqlRaiseError(), and DB_odbc::odbcRaiseError(). 01881 { 01882 if (isset($this->errorcode_map[$nativecode])) { 01883 return $this->errorcode_map[$nativecode]; 01884 } 01885 // Fall back to DB_ERROR if there was no mapping. 01886 return DB_ERROR; 01887 }
|
|
|
Maps a DB error code to a textual message
Definition at line 1902 of file common.php. References DB::errorMessage(). 01903 { 01904 return DB::errorMessage($this->errorcode_map[$dbcode]); 01905 }
|
|
|
Gets the DBMS' native error code produced by the last query
Reimplemented in DB_fbsql, DB_ibase, DB_ifx, DB_msql, DB_mssql, DB_mysql, DB_mysqli, DB_oci8, DB_odbc, DB_pgsql, DB_sqlite, and DB_sybase. Definition at line 1861 of file common.php. References DB_common::raiseError(). 01862 { 01863 return $this->raiseError(DB_ERROR_NOT_CAPABLE); 01864 }
|
|
|
Escapes a string according to the current DBMS's standards In SQLite, this makes things safe for inserts/updates, but may cause problems when performing text comparisons against columns containing binary data. See the PHP manual for more info.
Reimplemented in DB_msql, DB_mysql, DB_mysqli, DB_pgsql, and DB_sqlite. Definition at line 456 of file common.php. Referenced by quoteSmart(), and DB_common::quoteSmart().
|
|
||||||||||||
|
Executes a DB statement prepared with prepare()
Example 1.
Reimplemented in DB_ibase, and DB_oci8. Definition at line 952 of file common.php. References $result, $tmp, DB_common::executeEmulateQuery(), and DB::isError(). Referenced by DB_common::autoExecute(), DB_common::executeMultiple(), DB_common::getAll(), DB_common::getAssoc(), DB_common::getCol(), DB_common::getOne(), DB_common::getRow(), and DB_common::query(). 00953 { 00954 $realquery = $this->executeEmulateQuery($stmt, $data); 00955 if (DB::isError($realquery)) { 00956 return $realquery; 00957 } 00958 $result = $this->simpleQuery($realquery); 00959 00960 if ($result === DB_OK || DB::isError($result)) { 00961 return $result; 00962 } else { 00963 $tmp =& new DB_result($this, $result); 00964 return $tmp; 00965 } 00966 }
|
|
||||||||||||
|
Emulates executing prepared statements if the DBMS not support them
Definition at line 987 of file common.php. References $data, $fp, $i, $value, DB_common::quoteSmart(), and DB_common::raiseError(). Referenced by DB_common::execute(). 00988 { 00989 $stmt = (int)$stmt; 00990 $data = (array)$data; 00991 $this->last_parameters = $data; 00992 00993 if (count($this->prepare_types[$stmt]) != count($data)) { 00994 $this->last_query = $this->prepared_queries[$stmt]; 00995 return $this->raiseError(DB_ERROR_MISMATCH); 00996 } 00997 00998 $realquery = $this->prepare_tokens[$stmt][0]; 00999 01000 $i = 0; 01001 foreach ($data as $value) { 01002 if ($this->prepare_types[$stmt][$i] == DB_PARAM_SCALAR) { 01003 $realquery .= $this->quoteSmart($value); 01004 } elseif ($this->prepare_types[$stmt][$i] == DB_PARAM_OPAQUE) { 01005 $fp = @fopen($value, 'rb'); 01006 if (!$fp) { 01007 return $this->raiseError(DB_ERROR_ACCESS_VIOLATION); 01008 } 01009 $realquery .= $this->quoteSmart(fread($fp, filesize($value))); 01010 fclose($fp); 01011 } else { 01012 $realquery .= $value; 01013 } 01014 01015 $realquery .= $this->prepare_tokens[$stmt][++$i]; 01016 } 01017 01018 return $realquery; 01019 }
|
|
||||||||||||
|
Performs several execute() calls on the same statement handle $data must be an array indexed numerically from 0, one execute call is done for every "row" in the array. If an error occurs during execute(), executeMultiple() does not execute the unfinished rows, but rather returns that error.
Definition at line 1041 of file common.php. References DB_common::execute(), and DB::isError(). 01042 { 01043 foreach ($data as $value) { 01044 $res =& $this->execute($stmt, $value); 01045 if (DB::isError($res)) { 01046 return $res; 01047 } 01048 } 01049 return DB_OK; 01050 }
|
|
|
This method is used to tell which errors you expect to get. Expected errors are always returned with error mode PEAR_ERROR_RETURN. Expected error codes are stored in a stack, and this method pushes a new element onto it. The list of expected errors are in effect until they are popped off the stack with the popExpect() method. Note that this method can not be called statically
Definition at line 361 of file PEAR.php. 00362 { 00363 if (is_array($code)) { 00364 array_push($this->_expected_errors, $code); 00365 } else { 00366 array_push($this->_expected_errors, array($code)); 00367 } 00368 return sizeof($this->_expected_errors); 00369 }
|
|
||||||||||||||||||||
|
Places a row from the result set into the given array Formating of the array and the data therein are configurable. See DB_result::fetchInto() for more information. This method is not meant to be called directly. Use DB_result::fetchInto() instead. It can't be declared "protected" because DB_result is a separate object.
Definition at line 303 of file dbase.php. References $result, DB_common::_convertNullArrayValuesToEmpty(), and DB_common::_rtrimArrayValues(). 00304 { 00305 if ($rownum === null) { 00306 $rownum = $this->res_row[(int)$result]++; 00307 } 00308 if ($fetchmode & DB_FETCHMODE_ASSOC) { 00309 $arr = @dbase_get_record_with_names($this->connection, $rownum); 00310 if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) { 00311 $arr = array_change_key_case($arr, CASE_LOWER); 00312 } 00313 } else { 00314 $arr = @dbase_get_record($this->connection, $rownum); 00315 } 00316 if (!$arr) { 00317 return null; 00318 } 00319 if ($this->options['portability'] & DB_PORTABILITY_RTRIM) { 00320 $this->_rtrimArrayValues($arr); 00321 } 00322 if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) { 00323 $this->_convertNullArrayValuesToEmpty($arr); 00324 } 00325 return DB_OK; 00326 }
|
|
||||||||||||
|
Frees the internal resources associated with a prepared query
Reimplemented in DB_ibase, and DB_oci8. Definition at line 1067 of file common.php. Referenced by DB_common::autoExecute(), DB_common::getAll(), DB_common::getAssoc(), DB_common::getCol(), DB_common::getOne(), DB_common::getRow(), and DB_common::query(). |