]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/pear/DB/msql.php
locking table specific for better databases
[SourceForge/phpwiki.git] / lib / pear / DB / msql.php
1 <?php
2 //
3 // +----------------------------------------------------------------------+
4 // | PHP Version 4                                                        |
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 // +----------------------------------------------------------------------+
18 //
19 // $Id: msql.php,v 1.2 2004-04-26 20:44:37 rurban Exp $
20 //
21 // Database independent query interface definition for PHP's Mini-SQL
22 // extension.
23 //
24 // Based on DB 1.3 from the pear.php.net repository. 
25 // The only modifications made have been modification of the include paths. 
26 //
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');
29
30 require_once 'DB/common.php';
31
32 class DB_msql extends DB_common
33 {
34     var $connection;
35     var $phptype, $dbsyntax;
36     var $prepare_tokens = array();
37     var $prepare_types = array();
38
39     function DB_msql()
40     {
41         $this->DB_common();
42         $this->phptype = 'msql';
43         $this->dbsyntax = 'msql';
44         $this->features = array(
45             'prepare' => false,
46             'pconnect' => true,
47             'transactions' => false,
48             'limit' => 'emulate'
49         );
50     }
51
52     function connect($dsninfo, $persistent = false)
53     {
54         if (!DB::assertExtension('msql'))
55             return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
56
57         $this->dsn = $dsninfo;
58         $user = $dsninfo['username'];
59         $pw = $dsninfo['password'];
60         $dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost';
61
62         $connect_function = $persistent ? 'msql_pconnect' : 'msql_connect';
63
64         if ($dbhost && $user && $pw) {
65             $conn = $connect_function($dbhost, $user, $pw);
66         } elseif ($dbhost && $user) {
67             $conn = $connect_function($dbhost,$user);
68         } else {
69             $conn = $connect_function($dbhost);
70         }
71         if (!$conn) {
72             $this->raiseError(DB_ERROR_CONNECT_FAILED);
73         }
74         if (!@msql_select_db($dsninfo['database'], $conn)){
75             return $this->raiseError(DB_ERROR_NODBSELECTED);
76         }
77         $this->connection = $conn;
78         return DB_OK;
79     }
80
81     function disconnect()
82     {
83         $ret = @msql_close($this->connection);
84         $this->connection = null;
85         return $ret;
86     }
87
88     function simpleQuery($query)
89     {
90         $this->last_query = $query;
91         $query = $this->modifyQuery($query);
92         $result = @msql_query($query, $this->connection);
93         if (!$result) {
94             return $this->raiseError();
95         }
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;
99     }
100
101     // {{{ nextResult()
102
103     /**
104      * Move the internal msql result pointer to the next available result
105      *
106      * @param a valid fbsql result resource
107      *
108      * @access public
109      *
110      * @return true if a result is available otherwise return false
111      */
112     function nextResult($result)
113     {
114         return false;
115     }
116
117     // }}}
118
119     function fetchRow($result, $fetchmode = DB_FETCHMODE_DEFAULT, $rownum=null)
120     {
121         if ($fetchmode == DB_FETCHMODE_DEFAULT) {
122             $fetchmode = $this->fetchmode;
123         }
124         $res = $this->fetchInto ($result, $arr, $fetchmode, $rownum);
125         if ($res !== DB_OK) {
126             return $res;
127         }
128         return $arr;
129     }
130
131     function fetchInto($result, &$ar, $fetchmode, $rownum=null)
132     {
133         if ($rownum !== null) {
134             if (!@msql_data_seek($result, $rownum)) {
135                 return null;
136             }
137         }
138         if ($fetchmode & DB_FETCHMODE_ASSOC) {
139             $ar = @msql_fetch_array($result, MSQL_ASSOC);
140         } else {
141             $ar = @msql_fetch_row($result);
142         }
143         if (!$ar) {
144             if ($error = msql_error()) {
145                 return $this->raiseError($error);
146             } else {
147                 return null;
148             }
149         }
150         return DB_OK;
151     }
152
153     function freeResult($result)
154     {
155         if (is_resource($result)) {
156             return @msql_free_result($result);
157         }
158         if (!isset($this->prepare_tokens[$result])) {
159             return false;
160         }
161         unset($this->prepare_tokens[$result]);
162         unset($this->prepare_types[$result]);
163         return true;
164     }
165
166     function numCols($result)
167     {
168         $cols = @msql_num_fields($result);
169         if (!$cols) {
170             return $this->raiseError();
171         }
172         return $cols;
173     }
174
175     function numRows($result)
176     {
177         $rows = @msql_num_rows($result);
178         if (!$rows) {
179             return $this->raiseError();
180         }
181         return $rows;
182     }
183
184     /**
185      * Gets the number of rows affected by a query.
186      *
187      * @return number of rows affected by the last query
188      */
189
190     function affectedRows()
191     {
192         return @msql_affected_rows($this->connection);
193     }
194
195     // {{{ getSpecialQuery()
196
197     /**
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
201     */
202     function getSpecialQuery($type)
203     {
204         switch ($type) {
205             case 'tables':
206             default:
207                 return null;
208         }
209         return $sql;
210     }
211
212     // }}}
213
214 }
215 ?>