/[cvs]/nfo/php/libs/net.php.pear/DB/msql.php
ViewVC logotype

Annotation of /nfo/php/libs/net.php.pear/DB/msql.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.1 - (hide annotations)
Tue Oct 29 19:11:41 2002 UTC (21 years, 8 months ago) by cvsjoko
Branch: MAIN
CVS Tags: HEAD
+ new pear-libraries

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

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed