]> CyberLeo.Net >> Repos - SourceForge/phpwiki.git/blob - lib/pear/DB/msql.php
Remove svn:keywords
[SourceForge/phpwiki.git] / lib / pear / DB / msql.php
1 <?php
2 /* vim: set expandtab tabstop=4 shiftwidth=4 foldmethod=marker: */
3 // +----------------------------------------------------------------------+
4 // | PHP Version 4                                                        |
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 // +----------------------------------------------------------------------+
19
20 require_once 'DB/common.php';
21
22 /**
23  * Database independent query interface definition for PHP's Mini-SQL
24  * extension.
25  *
26  * @package  DB
27  * @version  
28  * @category Database
29  * @author   Sterling Hughes <sterling@php.net>
30  */
31 class DB_msql extends DB_common
32 {
33     // {{{ properties
34
35     var $connection;
36     var $phptype, $dbsyntax;
37     var $prepare_tokens = array();
38     var $prepare_types = array();
39
40     // }}}
41     // {{{ constructor
42
43     function DB_msql()
44     {
45         $this->DB_common();
46         $this->phptype = 'msql';
47         $this->dbsyntax = 'msql';
48         $this->features = array(
49             'prepare' => false,
50             'pconnect' => true,
51             'transactions' => false,
52             'limit' => 'emulate'
53         );
54     }
55
56     // }}}
57     // {{{ connect()
58
59     function connect($dsninfo, $persistent = false)
60     {
61         if (!DB::assertExtension('msql')) {
62             return $this->raiseError(DB_ERROR_EXTENSION_NOT_FOUND);
63         }
64
65         $this->dsn = $dsninfo;
66         $dbhost = $dsninfo['hostspec'] ? $dsninfo['hostspec'] : 'localhost';
67
68         $connect_function = $persistent ? 'msql_pconnect' : 'msql_connect';
69
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']);
75         } else {
76             $conn = $connect_function($dbhost);
77         }
78         if (!$conn) {
79             $this->raiseError(DB_ERROR_CONNECT_FAILED);
80         }
81         if (!@msql_select_db($dsninfo['database'], $conn)){
82             return $this->raiseError(DB_ERROR_NODBSELECTED);
83         }
84         $this->connection = $conn;
85         return DB_OK;
86     }
87
88     // }}}
89     // {{{ disconnect()
90
91     function disconnect()
92     {
93         $ret = @msql_close($this->connection);
94         $this->connection = null;
95         return $ret;
96     }
97
98     // }}}
99     // {{{ simpleQuery()
100
101     function simpleQuery($query)
102     {
103         $this->last_query = $query;
104         $query = $this->modifyQuery($query);
105         $result = @msql_query($query, $this->connection);
106         if (!$result) {
107             return $this->raiseError();
108         }
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;
112     }
113
114
115     // }}}
116     // {{{ nextResult()
117
118     /**
119      * Move the internal msql result pointer to the next available result
120      *
121      * @param a valid fbsql result resource
122      *
123      * @access public
124      *
125      * @return true if a result is available otherwise return false
126      */
127     function nextResult($result)
128     {
129         return false;
130     }
131
132     // }}}
133     // {{{ fetchInto()
134
135     /**
136      * Fetch a row and insert the data into an existing array.
137      *
138      * Formating of the array and the data therein are configurable.
139      * See DB_result::fetchInto() for more information.
140      *
141      * @param resource $result query result identifier
142      * @param array    $arr    (reference) array where data from the row
143      *                            should be placed
144      * @param int $fetchmode how the resulting array should be indexed
145      * @param int $rownum    the row number to fetch
146      *
147      * @return mixed DB_OK on success, null when end of result set is
148      *               reached or on failure
149      *
150      * @see DB_result::fetchInto()
151      * @access private
152      */
153     function fetchInto($result, &$arr, $fetchmode, $rownum=null)
154     {
155         if ($rownum !== null) {
156             if (!@msql_data_seek($result, $rownum)) {
157                 return null;
158             }
159         }
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);
164             }
165         } else {
166             $arr = @msql_fetch_row($result);
167         }
168         if (!$arr) {
169             if ($error = @msql_error()) {
170                 return $this->raiseError($error);
171             } else {
172                 return null;
173             }
174         }
175         if ($this->options['portability'] & DB_PORTABILITY_RTRIM) {
176             $this->_rtrimArrayValues($arr);
177         }
178         if ($this->options['portability'] & DB_PORTABILITY_NULL_TO_EMPTY) {
179             $this->_convertNullArrayValuesToEmpty($arr);
180         }
181         return DB_OK;
182     }
183
184     // }}}
185     // {{{ freeResult()
186
187     function freeResult($result)
188     {
189         return @msql_free_result($result);
190     }
191
192     // }}}
193     // {{{ numCols()
194
195     function numCols($result)
196     {
197         $cols = @msql_num_fields($result);
198         if (!$cols) {
199             return $this->raiseError();
200         }
201         return $cols;
202     }
203
204     // }}}
205     // {{{ numRows()
206
207     function numRows($result)
208     {
209         $rows = @msql_num_rows($result);
210         if (!$rows) {
211             return $this->raiseError();
212         }
213         return $rows;
214     }
215
216     // }}}
217     // {{{ affected()
218
219     /**
220      * Gets the number of rows affected by a query.
221      *
222      * @return number of rows affected by the last query
223      */
224     function affectedRows()
225     {
226         return @msql_affected_rows($this->connection);
227     }
228
229     // }}}
230
231 }
232
233 /*
234  * Local variables:
235  * tab-width: 4
236  * c-basic-offset: 4
237  * End:
238  */
239
240 ?>