3 // +----------------------------------------------------------------------+
5 // +----------------------------------------------------------------------+
6 // | Copyright (c) 1997-2002 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 // +----------------------------------------------------------------------+
19 // $Id: msql.php,v 1.2 2004-04-26 20:44:37 rurban Exp $
21 // Database independent query interface definition for PHP's Mini-SQL
24 // Based on DB 1.3 from the pear.php.net repository.
25 // The only modifications made have been modification of the include paths.
27 rcs_id('$Id: msql.php,v 1.2 2004-04-26 20:44:37 rurban Exp $');
28 rcs_id('From Pear CVS: Id: msql.php,v 1.3 2002/05/09 12:29:53 ssb Exp');
30 require_once 'DB/common.php';
32 class DB_msql extends DB_common
35 var $phptype, $dbsyntax;
36 var $prepare_tokens = array();
37 var $prepare_types = array();
42 $this->phptype = 'msql';
43 $this->dbsyntax = 'msql';
44 $this->features = array(
47 'transactions' => false,
52 function connect($dsninfo, $persistent = false)
54 if (!DB::assertExtension('msql'))
55 return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
57 $this->dsn = $dsninfo;
58 $user = $dsninfo['username'];
59 $pw = $dsninfo['password'];
60 $dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost';
62 $connect_function = $persistent ? 'msql_pconnect' : 'msql_connect';
64 if ($dbhost && $user && $pw) {
65 $conn = $connect_function($dbhost, $user, $pw);
66 } elseif ($dbhost && $user) {
67 $conn = $connect_function($dbhost,$user);
69 $conn = $connect_function($dbhost);
72 $this->raiseError(DB_ERROR_CONNECT_FAILED);
74 if (!@msql_select_db($dsninfo['database'], $conn)){
75 return $this->raiseError(DB_ERROR_NODBSELECTED);
77 $this->connection = $conn;
83 $ret = @msql_close($this->connection);
84 $this->connection = null;
88 function simpleQuery($query)
90 $this->last_query = $query;
91 $query = $this->modifyQuery($query);
92 $result = @msql_query($query, $this->connection);
94 return $this->raiseError();
96 // Determine which queries that should return data, and which
97 // should return an error code only.
98 return DB::isManip($query) ? DB_OK : $result;
104 * Move the internal msql result pointer to the next available result
106 * @param a valid fbsql result resource
110 * @return true if a result is available otherwise return false
112 function nextResult($result)
119 function fetchRow($result, $fetchmode = DB_FETCHMODE_DEFAULT, $rownum=null)
121 if ($fetchmode == DB_FETCHMODE_DEFAULT) {
122 $fetchmode = $this->fetchmode;
124 $res = $this->fetchInto ($result, $arr, $fetchmode, $rownum);
125 if ($res !== DB_OK) {
131 function fetchInto($result, &$ar, $fetchmode, $rownum=null)
133 if ($rownum !== null) {
134 if (!@msql_data_seek($result, $rownum)) {
138 if ($fetchmode & DB_FETCHMODE_ASSOC) {
139 $ar = @msql_fetch_array($result, MSQL_ASSOC);
141 $ar = @msql_fetch_row($result);
144 if ($error = msql_error()) {
145 return $this->raiseError($error);
153 function freeResult($result)
155 if (is_resource($result)) {
156 return @msql_free_result($result);
158 if (!isset($this->prepare_tokens[$result])) {
161 unset($this->prepare_tokens[$result]);
162 unset($this->prepare_types[$result]);
166 function numCols($result)
168 $cols = @msql_num_fields($result);
170 return $this->raiseError();
175 function numRows($result)
177 $rows = @msql_num_rows($result);
179 return $this->raiseError();
185 * Gets the number of rows affected by a query.
187 * @return number of rows affected by the last query
190 function affectedRows()
192 return @msql_affected_rows($this->connection);
195 // {{{ getSpecialQuery()
198 * Returns the query needed to get some backend info
199 * @param string $type What kind of info you want to retrieve
200 * @return string The SQL query string
202 function getSpecialQuery($type)