OSDN Git Service

ADDED: upgrade code for 3.5 in upgrades folder. Includes notices about end of PHP4...
[nucleus-jp/nucleus-jp-ancient.git] / utf8 / nucleus / libs / sql / mysql.php
1 <?php
2
3 /*
4  * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/)
5  * Copyright (C) 2002-2007 The Nucleus Group
6  *
7  * This program is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  * (see nucleus/documentation/index.html#license for more info)
12  */
13 /**
14  * @license http://nucleuscms.org/license.txt GNU General Public License
15  * @copyright Copyright (C) 2002-2007 The Nucleus Group
16  * @version $Id$
17  */
18  
19 /*
20  * complete sql_* wrappers for mysql functions
21  *
22  * functions moved from globalfunctions.php: sql_connect, sql_disconnect, sql_query
23  */
24
25
26 $MYSQL_CONN = 0;
27
28 if (function_exists('mysql_query') && !function_exists('sql_fetch_assoc'))
29 {
30     /**
31      *Errors before the database connection has been made
32      */
33     function startUpError($msg, $title) {
34         ?>
35 <html xmlns="http://www.w3.org/1999/xhtml">
36     <head><title><?php echo htmlspecialchars($title)?></title></head>
37     <body>
38         <h1><?php echo htmlspecialchars($title)?></h1>
39         <?php echo $msg?>
40     </body>
41 </html>
42 <?php
43         exit;
44     }
45
46     /**
47       * Connects to mysql server with arguments
48       */
49     function sql_connect_args($mysql_host = 'localhost', $mysql_user = '', $mysql_password = '', $mysql_database = '') {
50         
51         $CONN = @mysql_connect($mysql_host, $mysql_user, $mysql_password);
52         if ($mysql_database) mysql_select_db($mysql_database,$CONN);
53
54         return $CONN;
55     }
56     
57     /**
58       * Connects to mysql server
59       */
60     function sql_connect() {
61         global $MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD, $MYSQL_DATABASE, $MYSQL_CONN;
62
63         $MYSQL_CONN = @mysql_connect($MYSQL_HOST, $MYSQL_USER, $MYSQL_PASSWORD) or startUpError('<p>Could not connect to MySQL database.</p>', 'Connect Error');
64         mysql_select_db($MYSQL_DATABASE) or startUpError('<p>Could not select database: ' . mysql_error() . '</p>', 'Connect Error');
65
66 /*/ <add for garble measure>
67         $resource = sql_query("show variables LIKE 'character_set_database'");
68         $fetchDat = sql_fetch_assoc($resource);
69         $charset  = $fetchDat['Value'];
70         $mySqlVer = implode('.', array_map('intval', explode('.', sql_get_server_info($MYSQL_CONN))));
71         if ($mySqlVer >= '5.0.7' && phpversion() >= '5.2.3') {
72             mysql_set_charset($charset);
73         } elseif ($mySqlVer >= '4.1.0') {
74             sql_query("SET CHARACTER SET " . $charset);
75         }
76 // </add for garble measure>*/
77
78         return $MYSQL_CONN;
79     }
80
81     /**
82       * disconnects from SQL server
83       */
84     function sql_disconnect($conn = false) {
85         global $MYSQL_CONN;
86         if (!$conn) $conn = $MYSQL_CONN;
87         @mysql_close($conn);
88     }
89     
90     function sql_close($conn = false) {
91         global $MYSQL_CONN;
92         if (!$conn) $conn = $MYSQL_CONN;
93         @mysql_close($conn);
94     }
95     
96     /**
97       * executes an SQL query
98       */
99     function sql_query($query, $conn = false) {
100         global $SQLCount,$MYSQL_CONN;
101         if (!$conn) $conn = $MYSQL_CONN;
102         $SQLCount++;
103         $res = mysql_query($query,$conn) or print("mySQL error with query $query: " . mysql_error($conn) . '<p />');
104         return $res;
105     }
106     
107     /**
108       * executes an SQL error
109       */
110     function sql_error($conn = false)
111     {
112         global $MYSQL_CONN;
113         if (!$conn) $conn = $MYSQL_CONN;
114         return mysql_error($conn);
115     }
116     
117     /**
118       * executes an SQL db select
119       */
120     function sql_select_db($db,$conn = false)
121     {
122         global $MYSQL_CONN;
123         if (!$conn) $conn = $MYSQL_CONN;
124         return mysql_select_db($db,$conn);
125     }
126     
127     /**
128       * executes an SQL real escape 
129       */
130     function sql_real_escape_string($val,$conn = false)
131     {
132         global $MYSQL_CONN;
133         if (!$conn) $conn = $MYSQL_CONN;
134         return mysql_real_escape_string($val,$conn);
135     }
136     
137     /**
138       * executes an PDO::quote() like escape, ie adds quotes arround the string and escapes chars as needed 
139       */
140     function sql_quote_string($val,$conn = false) {
141         global $MYSQL_CONN;
142         if (!$conn) $conn = $MYSQL_CONN;
143         return "'".mysql_real_escape_string($val,$conn)."'";
144     }
145     
146     /**
147       * executes an SQL insert id
148       */
149     function sql_insert_id($conn = false)
150     {
151         global $MYSQL_CONN;
152         if (!$conn) $conn = $MYSQL_CONN;
153         return mysql_insert_id($conn);
154     }
155     
156     /**
157       * executes an SQL result request
158       */
159     function sql_result($res, $row, $col)
160     {
161         return mysql_result($res,$row,$col);
162     }
163     
164     /**
165       * frees sql result resources
166       */
167     function sql_free_result($res)
168     {
169         return mysql_free_result($res);
170     }
171     
172     /**
173       * returns number of rows in SQL result
174       */
175     function sql_num_rows($res)
176     {
177         return mysql_num_rows($res);
178     }
179     
180     /**
181       * returns number of rows affected by SQL query
182       */
183     function sql_affected_rows($res)
184     {
185         return mysql_affected_rows($res);
186     }
187     
188     /**
189       * Get number of fields in result
190       */
191     function sql_num_fields($res)
192     {
193         return mysql_num_fields($res);
194     }
195     
196     /**
197       * fetches next row of SQL result as an associative array
198       */
199     function sql_fetch_assoc($res)
200     {
201         return mysql_fetch_assoc($res);
202     }
203     
204     /**
205       * Fetch a result row as an associative array, a numeric array, or both
206       */
207     function sql_fetch_array($res)
208     {
209         return mysql_fetch_array($res);
210     }
211     
212     /**
213       * fetches next row of SQL result as an object
214       */
215     function sql_fetch_object($res)
216     {
217         return mysql_fetch_object($res);
218     }
219     
220     /**
221       * Get a result row as an enumerated array
222       */
223     function sql_fetch_row($res)
224     {
225         return mysql_fetch_row($res);
226     }
227     
228     /**
229       * Get column information from a result and return as an object
230       */
231     function sql_fetch_field($res,$offset = 0)
232     {
233         return mysql_fetch_field($res,$offset);
234     }
235     
236     /**
237       * Get current system status (returns string)
238       */
239     function sql_stat($conn=false)
240     {
241         global $MYSQL_CONN;
242         if (!$conn) $conn = $MYSQL_CONN;
243         return mysql_stat($conn);
244     }
245     
246     /**
247       * Returns the name of the character set
248       */
249     function sql_client_encoding($conn=false)
250     {
251         global $MYSQL_CONN;
252         if (!$conn) $conn = $MYSQL_CONN;
253         return mysql_client_encoding($conn);
254     }
255     
256     /**
257       * Get SQL client version
258       */
259     function sql_get_client_info()
260     {
261         return mysql_get_client_info();
262     }
263     
264     /**
265       * Get SQL server version
266       */
267     function sql_get_server_info($conn=false)
268     {
269         global $MYSQL_CONN;
270         if (!$conn) $conn = $MYSQL_CONN;
271         return mysql_get_server_info($conn);
272     }
273     
274     /**
275       * Returns a string describing the type of SQL connection in use for the connection or FALSE on failure
276       */
277     function sql_get_host_info($conn=false)
278     {
279         global $MYSQL_CONN;
280         if (!$conn) $conn = $MYSQL_CONN;
281         return mysql_get_host_info($conn);
282     }
283     
284     /**
285       * Returns the SQL protocol on success, or FALSE on failure. 
286       */
287     function sql_get_proto_info($conn=false)
288     {
289         global $MYSQL_CONN;
290         if (!$conn) $conn = $MYSQL_CONN;
291         return mysql_get_proto_info($conn);
292     }
293
294
295 /**************************************************************************
296     Unimplemented mysql_* functions
297     
298 # mysql_ data_ seek (maybe useful)
299 # mysql_ errno (maybe useful)
300 # mysql_ fetch_ lengths (maybe useful)
301 # mysql_ field_ flags (maybe useful)
302 # mysql_ field_ len (maybe useful)
303 # mysql_ field_ name (maybe useful)
304 # mysql_ field_ seek (maybe useful)
305 # mysql_ field_ table (maybe useful)
306 # mysql_ field_ type (maybe useful)
307 # mysql_ info (maybe useful)
308 # mysql_ list_ processes (maybe useful)
309 # mysql_ ping (maybe useful)
310 # mysql_ set_ charset (maybe useful, requires php >=5.2.3 and mysql >=5.0.7)
311 # mysql_ thread_ id (maybe useful)
312
313 # mysql_ db_ name (useful only if working on multiple dbs which we do not do)
314 # mysql_ list_ dbs (useful only if working on multiple dbs which we do not do)
315
316 # mysql_ pconnect (probably not useful and could cause some unintended performance issues)
317 # mysql_ unbuffered_ query (possibly useful, but complicated and not supported by all database drivers (pdo))
318
319 # mysql_ change_ user (deprecated)
320 # mysql_ create_ db (deprecated)
321 # mysql_ db_ query (deprecated)
322 # mysql_ drop_ db (deprecated)
323 # mysql_ escape_ string (deprecated)
324 # mysql_ list_ fields (deprecated)
325 # mysql_ list_ tables (deprecated)
326 # mysql_ tablename (deprecated)
327
328 *******************************************************************/
329
330
331 }
332 ?>