2 /* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
3 // +----------------------------------------------------------------------+
5 // +----------------------------------------------------------------------+
6 // | Copyright (c) 1997-2004 The PHP Group |
7 // +----------------------------------------------------------------------+
8 // | This source file is subject to version 2.02 of the PHP license, |
9 // | that is bundled with this package in the file LICENSE, and is |
10 // | available at through the world-wide-web at |
11 // | http://www.php.net/license/2_02.txt. |
12 // | If you did not receive a copy of the PHP license and are unable to |
13 // | obtain it through the world-wide-web, please send a note to |
14 // | license@php.net so we can mail you a copy immediately. |
15 // +----------------------------------------------------------------------+
16 // | Author: Tomas V.V.Cox <cox@idecnet.com> |
17 // | Maintainer: Daniel Convissor <danielc@php.net> |
18 // +----------------------------------------------------------------------+
21 // You have to compile your PHP with the --enable-dbase option
23 require_once 'DB/common.php';
26 * Database independent query interface definition for PHP's dbase
32 * @author Stig Bakken <ssb@php.net>
34 class DB_dbase extends DB_common
39 var $phptype, $dbsyntax;
40 var $prepare_tokens = array();
41 var $prepare_types = array();
42 var $res_row = array();
49 * DB_mysql constructor.
56 $this->phptype = 'dbase';
57 $this->dbsyntax = 'dbase';
58 $this->features = array(
61 'transactions' => false,
64 $this->errorcode_map = array();
70 function connect($dsninfo, $persistent = false)
72 if (!DB::assertExtension('dbase')) {
73 return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
75 $this->dsn = $dsninfo;
77 $conn = @dbase_open($dsninfo['database'], 0);
78 $error = ob_get_contents();
81 return $this->raiseError(DB_ERROR_CONNECT_FAILED, null,
82 null, null, strip_tags($error));
84 $this->connection = $conn;
93 $ret = @dbase_close($this->connection);
94 $this->connection = null;
101 function &query($query = null)
103 // emulate result resources
104 $this->res_row[$this->result] = 0;
105 $tmp =& new DB_result($this, $this->result++);
113 * Fetch a row and insert the data into an existing array.
115 * Formating of the array and the data therein are configurable.
116 * See DB_result::fetchInto() for more information.
118 * @param resource $result query result identifier
119 * @param array $arr (reference) array where data from the row
121 * @param int $fetchmode how the resulting array should be indexed
122 * @param int $rownum the row number to fetch
124 * @return mixed DB_OK on success, null when end of result set is
125 * reached or on failure
127 * @see DB_result::fetchInto()
130 function fetchInto($result, &$arr, $fetchmode, $rownum=null)
132 if ($rownum === null) {
133 $rownum = $this->res_row[$result]++;
135 if ($fetchmode & DB_FETCHMODE_ASSOC) {
136 $arr = @dbase_get_record_with_names($this->connection, $rownum);
137 if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) {
138 $arr = array_change_key_case($arr, CASE_LOWER);
141 $arr = @dbase_get_record($this->connection, $rownum);
146 if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
147 $this->_rtrimArrayValues($arr);
149 if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) {
150 $this->_convertNullArrayValuesToEmpty($arr);
158 function numCols($foo)
160 return @dbase_numfields($this->connection);
166 function numRows($foo)
168 return @dbase_numrecords($this->connection);
175 * Format input so it can be safely used in a query
177 * @param mixed $in data to be quoted
179 * @return mixed Submitted variable's type = returned value:
180 * + null = the string <samp>NULL</samp>
181 * + boolean = <samp>T</samp> if true or
182 * <samp>F</samp> if false. Use the <kbd>Logical</kbd>
184 * + integer or double = the unquoted number
185 * + other (including strings and numeric strings) =
186 * the data with single quotes escaped by preceeding
187 * single quotes then the whole string is encapsulated
188 * between single quotes
192 function quoteSmart($in)
194 if (is_int($in) || is_double($in)) {
196 } elseif (is_bool($in)) {
197 return $in ? 'T' : 'F';
198 } elseif (is_null($in)) {
201 return "'" . $this->escapeSimple($in) . "'";