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 // +----------------------------------------------------------------------+
22 require_once 'DB/common.php';
25 * Database independent query interface definition for PHP's Mini-SQL
31 * @author Sterling Hughes <sterling@php.net>
33 class DB_msql extends DB_common
38 var $phptype, $dbsyntax;
39 var $prepare_tokens = array();
40 var $prepare_types = array();
48 $this->phptype = 'msql';
49 $this->dbsyntax = 'msql';
50 $this->features = array(
53 'transactions' => false,
61 function connect($dsninfo, $persistent = false)
63 if (!DB::assertExtension('msql')) {
64 return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
67 $this->dsn = $dsninfo;
68 $dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost';
70 $connect_function = $persistent ? 'msql_pconnect' : 'msql_connect';
72 if ($dbhost && $dsninfo['username'] && $dsninfo['password']) {
73 $conn = $connect_function($dbhost, $dsninfo['username'],
74 $dsninfo['password']);
75 } elseif ($dbhost && $dsninfo['username']) {
76 $conn = $connect_function($dbhost, $dsninfo['username']);
78 $conn = $connect_function($dbhost);
81 $this->raiseError(DB_ERROR_CONNECT_FAILED);
83 if (!@msql_select_db($dsninfo['database'], $conn)){
84 return $this->raiseError(DB_ERROR_NODBSELECTED);
86 $this->connection = $conn;
95 $ret = @msql_close($this->connection);
96 $this->connection = null;
103 function simpleQuery($query)
105 $this->last_query = $query;
106 $query = $this->modifyQuery($query);
107 $result = @msql_query($query, $this->connection);
109 return $this->raiseError();
111 // Determine which queries that should return data, and which
112 // should return an error code only.
113 return DB::isManip($query) ? DB_OK : $result;
121 * Move the internal msql result pointer to the next available result
123 * @param a valid fbsql result resource
127 * @return true if a result is available otherwise return false
129 function nextResult($result)
138 * Fetch a row and insert the data into an existing array.
140 * Formating of the array and the data therein are configurable.
141 * See DB_result::fetchInto() for more information.
143 * @param resource $result query result identifier
144 * @param array $arr (reference) array where data from the row
146 * @param int $fetchmode how the resulting array should be indexed
147 * @param int $rownum the row number to fetch
149 * @return mixed DB_OK on success, null when end of result set is
150 * reached or on failure
152 * @see DB_result::fetchInto()
155 function fetchInto($result, &$arr, $fetchmode, $rownum=null)
157 if ($rownum !== null) {
158 if (!@msql_data_seek($result, $rownum)) {
162 if ($fetchmode & DB_FETCHMODE_ASSOC) {
163 $arr = @msql_fetch_array($result, MSQL_ASSOC);
164 if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE && $arr) {
165 $arr = array_change_key_case($arr, CASE_LOWER);
168 $arr = @msql_fetch_row($result);
171 if ($error = @msql_error()) {
172 return $this->raiseError($error);
177 if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
178 $this->_rtrimArrayValues($arr);
180 if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) {
181 $this->_convertNullArrayValuesToEmpty($arr);
189 function freeResult($result)
191 return @msql_free_result($result);
197 function numCols($result)
199 $cols = @msql_num_fields($result);
201 return $this->raiseError();
209 function numRows($result)
211 $rows = @msql_num_rows($result);
213 return $this->raiseError();
222 * Gets the number of rows affected by a query.
224 * @return number of rows affected by the last query
226 function affectedRows()
228 return @msql_affected_rows($this->connection);