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: Sterling Hughes <sterling@php.net> |
17 // | Maintainer: Daniel Convissor <danielc@php.net> |
18 // +----------------------------------------------------------------------+
20 require_once 'DB/common.php';
23 * Database independent query interface definition for PHP's Mini-SQL
29 * @author Sterling Hughes <sterling@php.net>
31 class DB_msql extends DB_common
36 var $phptype, $dbsyntax;
37 var $prepare_tokens = array();
38 var $prepare_types = array();
46 $this->phptype = 'msql';
47 $this->dbsyntax = 'msql';
48 $this->features = array(
51 'transactions' => false,
59 function connect($dsninfo, $persistent = false)
61 if (!DB::assertExtension('msql')) {
62 return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
65 $this->dsn = $dsninfo;
66 $dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost';
68 $connect_function = $persistent ? 'msql_pconnect' : 'msql_connect';
70 if ($dbhost && $dsninfo['username'] && $dsninfo['password']) {
71 $conn = $connect_function($dbhost, $dsninfo['username'],
72 $dsninfo['password']);
73 } elseif ($dbhost && $dsninfo['username']) {
74 $conn = $connect_function($dbhost, $dsninfo['username']);
76 $conn = $connect_function($dbhost);
79 $this->raiseError(DB_ERROR_CONNECT_FAILED);
81 if (!@msql_select_db($dsninfo['database'], $conn)){
82 return $this->raiseError(DB_ERROR_NODBSELECTED);
84 $this->connection = $conn;
93 $ret = @msql_close($this->connection);
94 $this->connection = null;
101 function simpleQuery($query)
103 $this->last_query = $query;
104 $query = $this->modifyQuery($query);
105 $result = @msql_query($query, $this->connection);
107 return $this->raiseError();
109 // Determine which queries that should return data, and which
110 // should return an error code only.
111 return DB::isManip($query) ? DB_OK : $result;
119 * Move the internal msql result pointer to the next available result
121 * @param a valid fbsql result resource
125 * @return true if a result is available otherwise return false
127 function nextResult($result)
136 * Fetch a row and insert the data into an existing array.
138 * Formating of the array and the data therein are configurable.
139 * See DB_result::fetchInto() for more information.
141 * @param resource $result query result identifier
142 * @param array $arr (reference) array where data from the row
144 * @param int $fetchmode how the resulting array should be indexed
145 * @param int $rownum the row number to fetch
147 * @return mixed DB_OK on success, null when end of result set is
148 * reached or on failure
150 * @see DB_result::fetchInto()
153 function fetchInto($result, &$arr, $fetchmode, $rownum=null)
155 if ($rownum !== null) {
156 if (!@msql_data_seek($result, $rownum)) {
160 if ($fetchmode & DB_FETCHMODE_ASSOC) {
161 $arr = @msql_fetch_array($result, MSQL_ASSOC);
162 if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) {
163 $arr = array_change_key_case($arr, CASE_LOWER);
166 $arr = @msql_fetch_row($result);
169 if ($error = @msql_error()) {
170 return $this->raiseError($error);
175 if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
176 $this->_rtrimArrayValues($arr);
178 if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) {
179 $this->_convertNullArrayValuesToEmpty($arr);
187 function freeResult($result)
189 return @msql_free_result($result);
195 function numCols($result)
197 $cols = @msql_num_fields($result);
199 return $this->raiseError();
207 function numRows($result)
209 $rows = @msql_num_rows($result);
211 return $this->raiseError();
220 * Gets the number of rows affected by a query.
222 * @return number of rows affected by the last query
224 function affectedRows()
226 return @msql_affected_rows($this->connection);