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 // +----------------------------------------------------------------------+
24 // You have to compile your PHP with the --enable-dbase option
27 require_once 'DB/common.php';
30 * Database independent query interface definition for PHP's dbase
36 * @author Stig Bakken <ssb@php.net>
38 class DB_dbase extends DB_common
43 var $phptype, $dbsyntax;
44 var $prepare_tokens = array();
45 var $prepare_types = array();
46 var $res_row = array();
53 * DB_mysql constructor.
60 $this->phptype = 'dbase';
61 $this->dbsyntax = 'dbase';
62 $this->features = array(
65 'transactions' => false,
68 $this->errorcode_map = array();
74 function connect($dsninfo, $persistent = false)
76 if (!DB::assertExtension('dbase')) {
77 return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
79 $this->dsn = $dsninfo;
81 $conn = @dbase_open($dsninfo['database'], 0);
82 $error = ob_get_contents();
85 return $this->raiseError(DB_ERROR_CONNECT_FAILED, null,
86 null, null, strip_tags($error));
88 $this->connection = $conn;
97 $ret = @dbase_close($this->connection);
98 $this->connection = null;
105 function &query($query = null)
107 // emulate result resources
108 $this->res_row[$this->result] = 0;
109 $tmp =& new DB_result($this, $this->result++);
117 * Fetch a row and insert the data into an existing array.
119 * Formating of the array and the data therein are configurable.
120 * See DB_result::fetchInto() for more information.
122 * @param resource $result query result identifier
123 * @param array $arr (reference) array where data from the row
125 * @param int $fetchmode how the resulting array should be indexed
126 * @param int $rownum the row number to fetch
128 * @return mixed DB_OK on success, null when end of result set is
129 * reached or on failure
131 * @see DB_result::fetchInto()
134 function fetchInto($result, &$arr, $fetchmode, $rownum=null)
136 if ($rownum === null) {
137 $rownum = $this->res_row[$result]++;
139 if ($fetchmode & DB_FETCHMODE_ASSOC) {
140 $arr = @dbase_get_record_with_names($this->connection, $rownum);
141 if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) {
142 $arr = array_change_key_case($arr, CASE_LOWER);
145 $arr = @dbase_get_record($this->connection, $rownum);
150 if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
151 $this->_rtrimArrayValues($arr);
153 if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) {
154 $this->_convertNullArrayValuesToEmpty($arr);
162 function numCols($foo)
164 return @dbase_numfields($this->connection);
170 function numRows($foo)
172 return @dbase_numrecords($this->connection);
179 * Format input so it can be safely used in a query
181 * @param mixed $in data to be quoted
183 * @return mixed Submitted variable's type = returned value:
184 * + null = the string <samp>NULL</samp>
185 * + boolean = <samp>T</samp> if true or
186 * <samp>F</samp> if false. Use the <kbd>Logical</kbd>
188 * + integer or double = the unquoted number
189 * + other (including strings and numeric strings) =
190 * the data with single quotes escaped by preceeding
191 * single quotes then the whole string is encapsulated
192 * between single quotes
196 function quoteSmart($in)
198 if (is_int($in) || is_double($in)) {
200 } elseif (is_bool($in)) {
201 return $in ? 'T' : 'F';
202 } elseif (is_null($in)) {
205 return "'" . $this->escapeSimple($in) . "'";