| [ Index ] |
PHP Cross Reference of Nucleus CMS v3.51 code documentation |
[Summary view] [Print] [Text view]
1 <?php 2 3 /* 4 * Nucleus: PHP/MySQL Weblog CMS (http://nucleuscms.org/) 5 * Copyright (C) 2002-2009 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-2009 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 return $MYSQL_CONN; 67 } 68 69 /** 70 * disconnects from SQL server 71 */ 72 function sql_disconnect($conn = false) { 73 global $MYSQL_CONN; 74 if (!$conn) $conn = $MYSQL_CONN; 75 @mysql_close($conn); 76 } 77 78 function sql_close($conn = false) { 79 global $MYSQL_CONN; 80 if (!$conn) $conn = $MYSQL_CONN; 81 @mysql_close($conn); 82 } 83 84 /** 85 * executes an SQL query 86 */ 87 function sql_query($query,$conn = false) { 88 global $SQLCount,$MYSQL_CONN; 89 if (!$conn) $conn = $MYSQL_CONN; 90 $SQLCount++; 91 $res = mysql_query($query,$conn) or print("mySQL error with query $query: " . mysql_error($conn) . '<p />'); 92 return $res; 93 } 94 95 /** 96 * executes an SQL error 97 */ 98 function sql_error($conn = false) 99 { 100 global $MYSQL_CONN; 101 if (!$conn) $conn = $MYSQL_CONN; 102 return mysql_error($conn); 103 } 104 105 /** 106 * executes an SQL db select 107 */ 108 function sql_select_db($db,$conn = false) 109 { 110 global $MYSQL_CONN; 111 if (!$conn) $conn = $MYSQL_CONN; 112 return mysql_select_db($db,$conn); 113 } 114 115 /** 116 * executes an SQL real escape 117 */ 118 function sql_real_escape_string($val,$conn = false) 119 { 120 global $MYSQL_CONN; 121 if (!$conn) $conn = $MYSQL_CONN; 122 return mysql_real_escape_string($val,$conn); 123 } 124 125 /** 126 * executes an PDO::quote() like escape, ie adds quotes arround the string and escapes chars as needed 127 */ 128 function sql_quote_string($val,$conn = false) { 129 global $MYSQL_CONN; 130 if (!$conn) $conn = $MYSQL_CONN; 131 return "'".mysql_real_escape_string($val,$conn)."'"; 132 } 133 134 /** 135 * executes an SQL insert id 136 */ 137 function sql_insert_id($conn = false) 138 { 139 global $MYSQL_CONN; 140 if (!$conn) $conn = $MYSQL_CONN; 141 return mysql_insert_id($conn); 142 } 143 144 /** 145 * executes an SQL result request 146 */ 147 function sql_result($res, $row, $col) 148 { 149 return mysql_result($res,$row,$col); 150 } 151 152 /** 153 * frees sql result resources 154 */ 155 function sql_free_result($res) 156 { 157 return mysql_free_result($res); 158 } 159 160 /** 161 * returns number of rows in SQL result 162 */ 163 function sql_num_rows($res) 164 { 165 return mysql_num_rows($res); 166 } 167 168 /** 169 * returns number of rows affected by SQL query 170 */ 171 function sql_affected_rows($res) 172 { 173 return mysql_affected_rows($res); 174 } 175 176 /** 177 * Get number of fields in result 178 */ 179 function sql_num_fields($res) 180 { 181 return mysql_num_fields($res); 182 } 183 184 /** 185 * fetches next row of SQL result as an associative array 186 */ 187 function sql_fetch_assoc($res) 188 { 189 return mysql_fetch_assoc($res); 190 } 191 192 /** 193 * Fetch a result row as an associative array, a numeric array, or both 194 */ 195 function sql_fetch_array($res) 196 { 197 return mysql_fetch_array($res); 198 } 199 200 /** 201 * fetches next row of SQL result as an object 202 */ 203 function sql_fetch_object($res) 204 { 205 return mysql_fetch_object($res); 206 } 207 208 /** 209 * Get a result row as an enumerated array 210 */ 211 function sql_fetch_row($res) 212 { 213 return mysql_fetch_row($res); 214 } 215 216 /** 217 * Get column information from a result and return as an object 218 */ 219 function sql_fetch_field($res,$offset = 0) 220 { 221 return mysql_fetch_field($res,$offset); 222 } 223 224 /** 225 * Get current system status (returns string) 226 */ 227 function sql_stat($conn=false) 228 { 229 global $MYSQL_CONN; 230 if (!$conn) $conn = $MYSQL_CONN; 231 return mysql_stat($conn); 232 } 233 234 /** 235 * Returns the name of the character set 236 */ 237 function sql_client_encoding($conn=false) 238 { 239 global $MYSQL_CONN; 240 if (!$conn) $conn = $MYSQL_CONN; 241 return mysql_client_encoding($conn); 242 } 243 244 /** 245 * Get SQL client version 246 */ 247 function sql_get_client_info() 248 { 249 return mysql_get_client_info(); 250 } 251 252 /** 253 * Get SQL server version 254 */ 255 function sql_get_server_info($conn=false) 256 { 257 global $MYSQL_CONN; 258 if (!$conn) $conn = $MYSQL_CONN; 259 return mysql_get_server_info($conn); 260 } 261 262 /** 263 * Returns a string describing the type of SQL connection in use for the connection or FALSE on failure 264 */ 265 function sql_get_host_info($conn=false) 266 { 267 global $MYSQL_CONN; 268 if (!$conn) $conn = $MYSQL_CONN; 269 return mysql_get_host_info($conn); 270 } 271 272 /** 273 * Returns the SQL protocol on success, or FALSE on failure. 274 */ 275 function sql_get_proto_info($conn=false) 276 { 277 global $MYSQL_CONN; 278 if (!$conn) $conn = $MYSQL_CONN; 279 return mysql_get_proto_info($conn); 280 } 281 282 /** 283 * Get the name of the specified field in a result 284 */ 285 function sql_field_name($res, $offset = 0) 286 { 287 return mysql_field_name($res, $offset); 288 } 289 290 /************************************************************************** 291 Unimplemented mysql_* functions 292 293 # mysql_ data_ seek (maybe useful) 294 # mysql_ errno (maybe useful) 295 # mysql_ fetch_ lengths (maybe useful) 296 # mysql_ field_ flags (maybe useful) 297 # mysql_ field_ len (maybe useful) 298 # mysql_ field_ seek (maybe useful) 299 # mysql_ field_ table (maybe useful) 300 # mysql_ field_ type (maybe useful) 301 # mysql_ info (maybe useful) 302 # mysql_ list_ processes (maybe useful) 303 # mysql_ ping (maybe useful) 304 # mysql_ set_ charset (maybe useful, requires php >=5.2.3 and mysql >=5.0.7) 305 # mysql_ thread_ id (maybe useful) 306 307 # mysql_ db_ name (useful only if working on multiple dbs which we do not do) 308 # mysql_ list_ dbs (useful only if working on multiple dbs which we do not do) 309 310 # mysql_ pconnect (probably not useful and could cause some unintended performance issues) 311 # mysql_ unbuffered_ query (possibly useful, but complicated and not supported by all database drivers (pdo)) 312 313 # mysql_ change_ user (deprecated) 314 # mysql_ create_ db (deprecated) 315 # mysql_ db_ query (deprecated) 316 # mysql_ drop_ db (deprecated) 317 # mysql_ escape_ string (deprecated) 318 # mysql_ list_ fields (deprecated) 319 # mysql_ list_ tables (deprecated) 320 # mysql_ tablename (deprecated) 321 322 *******************************************************************/ 323 324 325 } 326 ?>
title
Description
Body
title
Description
Body
title
Description
Body
title
Body
| Generated: Sun Aug 1 03:56:06 2010 |