mp-wp_genesis 1 <?php
mp-wp_genesis 2
mp-wp_genesis 3
mp-wp_genesis 4 /**
mp-wp_genesis 5 * WordPress DB Class
mp-wp_genesis 6 *
mp-wp_genesis 7 * Original code from {@link http://php.justinvincent.com Justin Vincent (justin@visunet.ie)}
mp-wp_genesis 8 *
mp-wp_genesis 9 * @package WordPress
mp-wp_genesis 10 * @subpackage Database
mp-wp_genesis 11 * @since 0.71
mp-wp_genesis 12 */
mp-wp_genesis 13
mp-wp_genesis 14 /**
mp-wp_genesis 15 * @since 0.71
mp-wp_genesis 16 */
mp-wp_genesis 17 define('EZSQL_VERSION', 'WP1.25');
mp-wp_genesis 18
mp-wp_genesis 19 /**
mp-wp_genesis 20 * @since 0.71
mp-wp_genesis 21 */
mp-wp_genesis 22 define('OBJECT', 'OBJECT', true);
mp-wp_genesis 23
mp-wp_genesis 24 /**
mp-wp_genesis 25 * @since {@internal Version Unknown}}
mp-wp_genesis 26 */
mp-wp_genesis 27 define('OBJECT_K', 'OBJECT_K', false);
mp-wp_genesis 28
mp-wp_genesis 29 /**
mp-wp_genesis 30 * @since 0.71
mp-wp_genesis 31 */
mp-wp_genesis 32 define('ARRAY_A', 'ARRAY_A', false);
mp-wp_genesis 33
mp-wp_genesis 34 /**
mp-wp_genesis 35 * @since 0.71
mp-wp_genesis 36 */
mp-wp_genesis 37 define('ARRAY_N', 'ARRAY_N', false);
mp-wp_genesis 38
mp-wp_genesis 39 /**
mp-wp_genesis 40 * WordPress Database Access Abstraction Object
mp-wp_genesis 41 *
mp-wp_genesis 42 * It is possible to replace this class with your own
mp-wp_genesis 43 * by setting the $wpdb global variable in wp-content/db.php
mp-wp_genesis 44 * file with your class. You can name it wpdb also, since
mp-wp_genesis 45 * this file will not be included, if the other file is
mp-wp_genesis 46 * available.
mp-wp_genesis 47 *
mp-wp_genesis 48 * @link http://codex.wordpress.org/Function_Reference/wpdb_Class
mp-wp_genesis 49 *
mp-wp_genesis 50 * @package WordPress
mp-wp_genesis 51 * @subpackage Database
mp-wp_genesis 52 * @since 0.71
mp-wp_genesis 53 * @final
mp-wp_genesis 54 */
mp-wp_genesis 55 class wpdb {
mp-wp_genesis 56
mp-wp_genesis 57 /**
mp-wp_genesis 58 * Whether to show SQL/DB errors
mp-wp_genesis 59 *
mp-wp_genesis 60 * @since 0.71
mp-wp_genesis 61 * @access private
mp-wp_genesis 62 * @var bool
mp-wp_genesis 63 */
mp-wp_genesis 64 var $show_errors = false;
mp-wp_genesis 65
mp-wp_genesis 66 /**
mp-wp_genesis 67 * Whether to suppress errors during the DB bootstrapping.
mp-wp_genesis 68 *
mp-wp_genesis 69 * @access private
mp-wp_genesis 70 * @since {@internal Version Unknown}}
mp-wp_genesis 71 * @var bool
mp-wp_genesis 72 */
mp-wp_genesis 73 var $suppress_errors = false;
mp-wp_genesis 74
mp-wp_genesis 75 /**
mp-wp_genesis 76 * The last error during query.
mp-wp_genesis 77 *
mp-wp_genesis 78 * @since {@internal Version Unknown}}
mp-wp_genesis 79 * @var string
mp-wp_genesis 80 */
mp-wp_genesis 81 var $last_error = '';
mp-wp_genesis 82
mp-wp_genesis 83 /**
mp-wp_genesis 84 * Amount of queries made
mp-wp_genesis 85 *
mp-wp_genesis 86 * @since 1.2.0
mp-wp_genesis 87 * @access private
mp-wp_genesis 88 * @var int
mp-wp_genesis 89 */
mp-wp_genesis 90 var $num_queries = 0;
mp-wp_genesis 91
mp-wp_genesis 92 /**
mp-wp_genesis 93 * Saved result of the last query made
mp-wp_genesis 94 *
mp-wp_genesis 95 * @since 1.2.0
mp-wp_genesis 96 * @access private
mp-wp_genesis 97 * @var array
mp-wp_genesis 98 */
mp-wp_genesis 99 var $last_query;
mp-wp_genesis 100
mp-wp_genesis 101 /**
mp-wp_genesis 102 * Saved info on the table column
mp-wp_genesis 103 *
mp-wp_genesis 104 * @since 1.2.0
mp-wp_genesis 105 * @access private
mp-wp_genesis 106 * @var array
mp-wp_genesis 107 */
mp-wp_genesis 108 var $col_info;
mp-wp_genesis 109
mp-wp_genesis 110 /**
mp-wp_genesis 111 * Saved queries that were executed
mp-wp_genesis 112 *
mp-wp_genesis 113 * @since 1.5.0
mp-wp_genesis 114 * @access private
mp-wp_genesis 115 * @var array
mp-wp_genesis 116 */
mp-wp_genesis 117 var $queries;
mp-wp_genesis 118
mp-wp_genesis 119 /**
mp-wp_genesis 120 * WordPress table prefix
mp-wp_genesis 121 *
mp-wp_genesis 122 * You can set this to have multiple WordPress installations
mp-wp_genesis 123 * in a single database. The second reason is for possible
mp-wp_genesis 124 * security precautions.
mp-wp_genesis 125 *
mp-wp_genesis 126 * @since 0.71
mp-wp_genesis 127 * @access private
mp-wp_genesis 128 * @var string
mp-wp_genesis 129 */
mp-wp_genesis 130 var $prefix = '';
mp-wp_genesis 131
mp-wp_genesis 132 /**
mp-wp_genesis 133 * Whether the database queries are ready to start executing.
mp-wp_genesis 134 *
mp-wp_genesis 135 * @since 2.5.0
mp-wp_genesis 136 * @access private
mp-wp_genesis 137 * @var bool
mp-wp_genesis 138 */
mp-wp_genesis 139 var $ready = false;
mp-wp_genesis 140
mp-wp_genesis 141 /**
mp-wp_genesis 142 * WordPress Posts table
mp-wp_genesis 143 *
mp-wp_genesis 144 * @since 1.5.0
mp-wp_genesis 145 * @access public
mp-wp_genesis 146 * @var string
mp-wp_genesis 147 */
mp-wp_genesis 148 var $posts;
mp-wp_genesis 149
mp-wp_genesis 150 /**
mp-wp_genesis 151 * WordPress Users table
mp-wp_genesis 152 *
mp-wp_genesis 153 * @since 1.5.0
mp-wp_genesis 154 * @access public
mp-wp_genesis 155 * @var string
mp-wp_genesis 156 */
mp-wp_genesis 157 var $users;
mp-wp_genesis 158
mp-wp_genesis 159 /**
mp-wp_genesis 160 * WordPress Categories table
mp-wp_genesis 161 *
mp-wp_genesis 162 * @since 1.5.0
mp-wp_genesis 163 * @access public
mp-wp_genesis 164 * @var string
mp-wp_genesis 165 */
mp-wp_genesis 166 var $categories;
mp-wp_genesis 167
mp-wp_genesis 168 /**
mp-wp_genesis 169 * WordPress Post to Category table
mp-wp_genesis 170 *
mp-wp_genesis 171 * @since 1.5.0
mp-wp_genesis 172 * @access public
mp-wp_genesis 173 * @var string
mp-wp_genesis 174 */
mp-wp_genesis 175 var $post2cat;
mp-wp_genesis 176
mp-wp_genesis 177 /**
mp-wp_genesis 178 * WordPress Comments table
mp-wp_genesis 179 *
mp-wp_genesis 180 * @since 1.5.0
mp-wp_genesis 181 * @access public
mp-wp_genesis 182 * @var string
mp-wp_genesis 183 */
mp-wp_genesis 184 var $comments;
mp-wp_genesis 185
mp-wp_genesis 186 /**
mp-wp_genesis 187 * WordPress Links table
mp-wp_genesis 188 *
mp-wp_genesis 189 * @since 1.5.0
mp-wp_genesis 190 * @access public
mp-wp_genesis 191 * @var string
mp-wp_genesis 192 */
mp-wp_genesis 193 var $links;
mp-wp_genesis 194
mp-wp_genesis 195 /**
mp-wp_genesis 196 * WordPress Options table
mp-wp_genesis 197 *
mp-wp_genesis 198 * @since 1.5.0
mp-wp_genesis 199 * @access public
mp-wp_genesis 200 * @var string
mp-wp_genesis 201 */
mp-wp_genesis 202 var $options;
mp-wp_genesis 203
mp-wp_genesis 204 /**
mp-wp_genesis 205 * WordPress Post Metadata table
mp-wp_genesis 206 *
mp-wp_genesis 207 * @since {@internal Version Unknown}}
mp-wp_genesis 208 * @access public
mp-wp_genesis 209 * @var string
mp-wp_genesis 210 */
mp-wp_genesis 211 var $postmeta;
mp-wp_genesis 212
mp-wp_genesis 213 /**
mp-wp_genesis 214 * WordPress User Metadata table
mp-wp_genesis 215 *
mp-wp_genesis 216 * @since 2.3.0
mp-wp_genesis 217 * @access public
mp-wp_genesis 218 * @var string
mp-wp_genesis 219 */
mp-wp_genesis 220 var $usermeta;
mp-wp_genesis 221
mp-wp_genesis 222 /**
mp-wp_genesis 223 * WordPress Terms table
mp-wp_genesis 224 *
mp-wp_genesis 225 * @since 2.3.0
mp-wp_genesis 226 * @access public
mp-wp_genesis 227 * @var string
mp-wp_genesis 228 */
mp-wp_genesis 229 var $terms;
mp-wp_genesis 230
mp-wp_genesis 231 /**
mp-wp_genesis 232 * WordPress Term Taxonomy table
mp-wp_genesis 233 *
mp-wp_genesis 234 * @since 2.3.0
mp-wp_genesis 235 * @access public
mp-wp_genesis 236 * @var string
mp-wp_genesis 237 */
mp-wp_genesis 238 var $term_taxonomy;
mp-wp_genesis 239
mp-wp_genesis 240 /**
mp-wp_genesis 241 * WordPress Term Relationships table
mp-wp_genesis 242 *
mp-wp_genesis 243 * @since 2.3.0
mp-wp_genesis 244 * @access public
mp-wp_genesis 245 * @var string
mp-wp_genesis 246 */
mp-wp_genesis 247 var $term_relationships;
mp-wp_genesis 248
mp-wp_genesis 249 /**
mp-wp_genesis 250 * List of WordPress tables
mp-wp_genesis 251 *
mp-wp_genesis 252 * @since {@internal Version Unknown}}
mp-wp_genesis 253 * @access private
mp-wp_genesis 254 * @var array
mp-wp_genesis 255 */
mp-wp_genesis 256 var $tables = array('users', 'usermeta', 'posts', 'categories', 'post2cat', 'comments', 'links', 'link2cat', 'options',
mp-wp_genesis 257 'postmeta', 'terms', 'term_taxonomy', 'term_relationships');
mp-wp_genesis 258
mp-wp_genesis 259 /**
mp-wp_genesis 260 * Database table columns charset
mp-wp_genesis 261 *
mp-wp_genesis 262 * @since 2.2.0
mp-wp_genesis 263 * @access public
mp-wp_genesis 264 * @var string
mp-wp_genesis 265 */
mp-wp_genesis 266 var $charset;
mp-wp_genesis 267
mp-wp_genesis 268 /**
mp-wp_genesis 269 * Database table columns collate
mp-wp_genesis 270 *
mp-wp_genesis 271 * @since 2.2.0
mp-wp_genesis 272 * @access public
mp-wp_genesis 273 * @var string
mp-wp_genesis 274 */
mp-wp_genesis 275 var $collate;
mp-wp_genesis 276
mp-wp_genesis 277 /**
mp-wp_genesis 278 * Connects to the database server and selects a database
mp-wp_genesis 279 *
mp-wp_genesis 280 * PHP4 compatibility layer for calling the PHP5 constructor.
mp-wp_genesis 281 *
mp-wp_genesis 282 * @uses wpdb::__construct() Passes parameters and returns result
mp-wp_genesis 283 * @since 0.71
mp-wp_genesis 284 *
mp-wp_genesis 285 * @param string $dbuser MySQL database user
mp-wp_genesis 286 * @param string $dbpassword MySQL database password
mp-wp_genesis 287 * @param string $dbname MySQL database name
mp-wp_genesis 288 * @param string $dbhost MySQL database host
mp-wp_genesis 289 */
mp-wp_genesis 290 function wpdb($dbuser, $dbpassword, $dbname, $dbhost) {
mp-wp_genesis 291 return $this->__construct($dbuser, $dbpassword, $dbname, $dbhost);
mp-wp_genesis 292 }
mp-wp_genesis 293
mp-wp_genesis 294 /**
mp-wp_genesis 295 * Connects to the database server and selects a database
mp-wp_genesis 296 *
mp-wp_genesis 297 * PHP5 style constructor for compatibility with PHP5. Does
mp-wp_genesis 298 * the actual setting up of the class properties and connection
mp-wp_genesis 299 * to the database.
mp-wp_genesis 300 *
mp-wp_genesis 301 * @since 2.0.8
mp-wp_genesis 302 *
mp-wp_genesis 303 * @param string $dbuser MySQL database user
mp-wp_genesis 304 * @param string $dbpassword MySQL database password
mp-wp_genesis 305 * @param string $dbname MySQL database name
mp-wp_genesis 306 * @param string $dbhost MySQL database host
mp-wp_genesis 307 */
mp-wp_genesis 308 function __construct($dbuser, $dbpassword, $dbname, $dbhost) {
mp-wp_genesis 309 register_shutdown_function(array(&$this, "__destruct"));
mp-wp_genesis 310
mp-wp_genesis 311 if ( defined('WP_DEBUG') and WP_DEBUG == true )
mp-wp_genesis 312 $this->show_errors();
mp-wp_genesis 313
mp-wp_genesis 314 if ( defined('DB_CHARSET') )
mp-wp_genesis 315 $this->charset = DB_CHARSET;
mp-wp_genesis 316
mp-wp_genesis 317 if ( defined('DB_COLLATE') )
mp-wp_genesis 318 $this->collate = DB_COLLATE;
mp-wp_genesis 319
mp-wp_genesis 320 $this->dbh = @mysql_connect($dbhost, $dbuser, $dbpassword, true);
mp-wp_genesis 321 if (!$this->dbh) {
mp-wp_genesis 322 $this->bail(sprintf(/*WP_I18N_DB_CONN_ERROR*/"
mp-wp_genesis 323 <h1>Error establishing a database connection</h1>
mp-wp_genesis 324 <p>This either means that the username and password information in your <code>wp-config.php</code> file is incorrect or we can't contact the database server at <code>%s</code>. This could mean your host's database server is down.</p>
mp-wp_genesis 325 <ul>
mp-wp_genesis 326 <li>Are you sure you have the correct username and password?</li>
mp-wp_genesis 327 <li>Are you sure that you have typed the correct hostname?</li>
mp-wp_genesis 328 <li>Are you sure that the database server is running?</li>
mp-wp_genesis 329 </ul>
mp-wp_genesis 330 <p>If you're unsure what these terms mean you should probably contact your host. If you still need help you can always visit the <a href='http://wordpress.org/support/'>WordPress Support Forums</a>.</p>
mp-wp_genesis 331 "/*/WP_I18N_DB_CONN_ERROR*/, $dbhost));
mp-wp_genesis 332 return;
mp-wp_genesis 333 }
mp-wp_genesis 334
mp-wp_genesis 335 $this->ready = true;
mp-wp_genesis 336
mp-wp_genesis 337 if ( $this->has_cap( 'collation' ) ) {
mp-wp_genesis 338 $collation_query = '';
mp-wp_genesis 339 if ( !empty($this->charset) ) {
mp-wp_genesis 340 $collation_query = "SET NAMES '{$this->charset}'";
mp-wp_genesis 341 if (!empty($this->collate) )
mp-wp_genesis 342 $collation_query .= " COLLATE '{$this->collate}'";
mp-wp_genesis 343 }
mp-wp_genesis 344
mp-wp_genesis 345 if ( !empty($collation_query) )
mp-wp_genesis 346 $this->query($collation_query);
mp-wp_genesis 347
mp-wp_genesis 348 }
mp-wp_genesis 349
mp-wp_genesis 350 $this->select($dbname);
mp-wp_genesis 351 }
mp-wp_genesis 352
mp-wp_genesis 353 /**
mp-wp_genesis 354 * PHP5 style destructor and will run when database object is destroyed.
mp-wp_genesis 355 *
mp-wp_genesis 356 * @since 2.0.8
mp-wp_genesis 357 *
mp-wp_genesis 358 * @return bool Always true
mp-wp_genesis 359 */
mp-wp_genesis 360 function __destruct() {
mp-wp_genesis 361 return true;
mp-wp_genesis 362 }
mp-wp_genesis 363
mp-wp_genesis 364 /**
mp-wp_genesis 365 * Sets the table prefix for the WordPress tables.
mp-wp_genesis 366 *
mp-wp_genesis 367 * Also allows for the CUSTOM_USER_TABLE and CUSTOM_USER_META_TABLE to
mp-wp_genesis 368 * override the WordPress users and usersmeta tables.
mp-wp_genesis 369 *
mp-wp_genesis 370 * @since 2.5.0
mp-wp_genesis 371 *
mp-wp_genesis 372 * @param string $prefix Alphanumeric name for the new prefix.
mp-wp_genesis 373 * @return string Old prefix
mp-wp_genesis 374 */
mp-wp_genesis 375 function set_prefix($prefix) {
mp-wp_genesis 376
mp-wp_genesis 377 if ( preg_match('|[^a-z0-9_]|i', $prefix) )
mp-wp_genesis 378 return new WP_Error('invalid_db_prefix', /*WP_I18N_DB_BAD_PREFIX*/'Invalid database prefix'/*/WP_I18N_DB_BAD_PREFIX*/);
mp-wp_genesis 379
mp-wp_genesis 380 $old_prefix = $this->prefix;
mp-wp_genesis 381 $this->prefix = $prefix;
mp-wp_genesis 382
mp-wp_genesis 383 foreach ( (array) $this->tables as $table )
mp-wp_genesis 384 $this->$table = $this->prefix . $table;
mp-wp_genesis 385
mp-wp_genesis 386 if ( defined('CUSTOM_USER_TABLE') )
mp-wp_genesis 387 $this->users = CUSTOM_USER_TABLE;
mp-wp_genesis 388
mp-wp_genesis 389 if ( defined('CUSTOM_USER_META_TABLE') )
mp-wp_genesis 390 $this->usermeta = CUSTOM_USER_META_TABLE;
mp-wp_genesis 391
mp-wp_genesis 392 return $old_prefix;
mp-wp_genesis 393 }
mp-wp_genesis 394
mp-wp_genesis 395 /**
mp-wp_genesis 396 * Selects a database using the current database connection.
mp-wp_genesis 397 *
mp-wp_genesis 398 * The database name will be changed based on the current database
mp-wp_genesis 399 * connection. On failure, the execution will bail and display an DB error.
mp-wp_genesis 400 *
mp-wp_genesis 401 * @since 0.71
mp-wp_genesis 402 *
mp-wp_genesis 403 * @param string $db MySQL database name
mp-wp_genesis 404 * @return null Always null.
mp-wp_genesis 405 */
mp-wp_genesis 406 function select($db) {
mp-wp_genesis 407 if (!@mysql_select_db($db, $this->dbh)) {
mp-wp_genesis 408 $this->ready = false;
mp-wp_genesis 409 $this->bail(sprintf(/*WP_I18N_DB_SELECT_DB*/'
mp-wp_genesis 410 <h1>Can’t select database</h1>
mp-wp_genesis 411 <p>We were able to connect to the database server (which means your username and password is okay) but not able to select the <code>%1$s</code> database.</p>
mp-wp_genesis 412 <ul>
mp-wp_genesis 413 <li>Are you sure it exists?</li>
mp-wp_genesis 414 <li>Does the user <code>%2$s</code> have permission to use the <code>%1$s</code> database?</li>
mp-wp_genesis 415 <li>On some systems the name of your database is prefixed with your username, so it would be like <code>username_%1$s</code>. Could that be the problem?</li>
mp-wp_genesis 416 </ul>
mp-wp_genesis 417 <p>If you don\'t know how to setup a database you should <strong>contact your host</strong>. If all else fails you may find help at the <a href="http://wordpress.org/support/">WordPress Support Forums</a>.</p>'/*/WP_I18N_DB_SELECT_DB*/, $db, DB_USER));
mp-wp_genesis 418 return;
mp-wp_genesis 419 }
mp-wp_genesis 420 }
mp-wp_genesis 421
mp-wp_genesis 422 /**
mp-wp_genesis 423 * Escapes content for insertion into the database, for security
mp-wp_genesis 424 *
mp-wp_genesis 425 * @since 0.71
mp-wp_genesis 426 *
mp-wp_genesis 427 * @param string $string
mp-wp_genesis 428 * @return string query safe string
mp-wp_genesis 429 */
mp-wp_genesis 430 function escape($string) {
mp-wp_genesis 431 return addslashes( $string );
mp-wp_genesis 432 // Disable rest for now, causing problems
mp-wp_genesis 433 /*
mp-wp_genesis 434 if( !$this->dbh || version_compare( phpversion(), '4.3.0' ) == '-1' )
mp-wp_genesis 435 return mysql_escape_string( $string );
mp-wp_genesis 436 else
mp-wp_genesis 437 return mysql_real_escape_string( $string, $this->dbh );
mp-wp_genesis 438 */
mp-wp_genesis 439 }
mp-wp_genesis 440
mp-wp_genesis 441 /**
mp-wp_genesis 442 * Escapes content by reference for insertion into the database, for security
mp-wp_genesis 443 *
mp-wp_genesis 444 * @since 2.3.0
mp-wp_genesis 445 *
mp-wp_genesis 446 * @param string $s
mp-wp_genesis 447 */
mp-wp_genesis 448 function escape_by_ref(&$s) {
mp-wp_genesis 449 $s = $this->escape($s);
mp-wp_genesis 450 }
mp-wp_genesis 451
mp-wp_genesis 452 /**
mp-wp_genesis 453 * Prepares a SQL query for safe use, using sprintf() syntax.
mp-wp_genesis 454 *
mp-wp_genesis 455 * @link http://php.net/sprintf See for syntax to use for query string.
mp-wp_genesis 456 * @since 2.3.0
mp-wp_genesis 457 *
mp-wp_genesis 458 * @param null|string $args If string, first parameter must be query statement
mp-wp_genesis 459 * @param mixed $args,... If additional parameters, they will be set inserted into the query.
mp-wp_genesis 460 * @return null|string Sanitized query string
mp-wp_genesis 461 */
mp-wp_genesis 462 function prepare($args=null) {
mp-wp_genesis 463 if ( is_null( $args ) )
mp-wp_genesis 464 return;
mp-wp_genesis 465 $args = func_get_args();
mp-wp_genesis 466 $query = array_shift($args);
mp-wp_genesis 467 $query = str_replace("'%s'", '%s', $query); // in case someone mistakenly already singlequoted it
mp-wp_genesis 468 $query = str_replace('"%s"', '%s', $query); // doublequote unquoting
mp-wp_genesis 469 $query = str_replace('%s', "'%s'", $query); // quote the strings
mp-wp_genesis 470 array_walk($args, array(&$this, 'escape_by_ref'));
mp-wp_genesis 471 return @vsprintf($query, $args);
mp-wp_genesis 472 }
mp-wp_genesis 473
mp-wp_genesis 474 /**
mp-wp_genesis 475 * Print SQL/DB error.
mp-wp_genesis 476 *
mp-wp_genesis 477 * @since 0.71
mp-wp_genesis 478 * @global array $EZSQL_ERROR Stores error information of query and error string
mp-wp_genesis 479 *
mp-wp_genesis 480 * @param string $str The error to display
mp-wp_genesis 481 * @return bool False if the showing of errors is disabled.
mp-wp_genesis 482 */
mp-wp_genesis 483 function print_error($str = '') {
mp-wp_genesis 484 global $EZSQL_ERROR;
mp-wp_genesis 485
mp-wp_genesis 486 if (!$str) $str = mysql_error($this->dbh);
mp-wp_genesis 487 $EZSQL_ERROR[] = array ('query' => $this->last_query, 'error_str' => $str);
mp-wp_genesis 488
mp-wp_genesis 489 if ( $this->suppress_errors )
mp-wp_genesis 490 return false;
mp-wp_genesis 491
mp-wp_genesis 492 if ( $caller = $this->get_caller() )
mp-wp_genesis 493 $error_str = sprintf(/*WP_I18N_DB_QUERY_ERROR_FULL*/'WordPress database error %1$s for query %2$s made by %3$s'/*/WP_I18N_DB_QUERY_ERROR_FULL*/, $str, $this->last_query, $caller);
mp-wp_genesis 494 else
mp-wp_genesis 495 $error_str = sprintf(/*WP_I18N_DB_QUERY_ERROR*/'WordPress database error %1$s for query %2$s'/*/WP_I18N_DB_QUERY_ERROR*/, $str, $this->last_query);
mp-wp_genesis 496
mp-wp_genesis 497 $log_error = true;
mp-wp_genesis 498 if ( ! function_exists('error_log') )
mp-wp_genesis 499 $log_error = false;
mp-wp_genesis 500
mp-wp_genesis 501 $log_file = @ini_get('error_log');
mp-wp_genesis 502 if ( !empty($log_file) && ('syslog' != $log_file) && !@is_writable($log_file) )
mp-wp_genesis 503 $log_error = false;
mp-wp_genesis 504
mp-wp_genesis 505 if ( $log_error )
mp-wp_genesis 506 @error_log($error_str, 0);
mp-wp_genesis 507
mp-wp_genesis 508 // Is error output turned on or not..
mp-wp_genesis 509 if ( !$this->show_errors )
mp-wp_genesis 510 return false;
mp-wp_genesis 511
mp-wp_genesis 512 $str = htmlspecialchars($str, ENT_QUOTES);
mp-wp_genesis 513 $query = htmlspecialchars($this->last_query, ENT_QUOTES);
mp-wp_genesis 514
mp-wp_genesis 515 // If there is an error then take note of it
mp-wp_genesis 516 print "<div id='error'>
mp-wp_genesis 517 <p class='wpdberror'><strong>WordPress database error:</strong> [$str]<br />
mp-wp_genesis 518 <code>$query</code></p>
mp-wp_genesis 519 </div>";
mp-wp_genesis 520 }
mp-wp_genesis 521
mp-wp_genesis 522 /**
mp-wp_genesis 523 * Enables showing of database errors.
mp-wp_genesis 524 *
mp-wp_genesis 525 * This function should be used only to enable showing of errors.
mp-wp_genesis 526 * wpdb::hide_errors() should be used instead for hiding of errors. However,
mp-wp_genesis 527 * this function can be used to enable and disable showing of database
mp-wp_genesis 528 * errors.
mp-wp_genesis 529 *
mp-wp_genesis 530 * @since 0.71
mp-wp_genesis 531 *
mp-wp_genesis 532 * @param bool $show Whether to show or hide errors
mp-wp_genesis 533 * @return bool Old value for showing errors.
mp-wp_genesis 534 */
mp-wp_genesis 535 function show_errors( $show = true ) {
mp-wp_genesis 536 $errors = $this->show_errors;
mp-wp_genesis 537 $this->show_errors = $show;
mp-wp_genesis 538 return $errors;
mp-wp_genesis 539 }
mp-wp_genesis 540
mp-wp_genesis 541 /**
mp-wp_genesis 542 * Disables showing of database errors.
mp-wp_genesis 543 *
mp-wp_genesis 544 * @since 0.71
mp-wp_genesis 545 *
mp-wp_genesis 546 * @return bool Whether showing of errors was active or not
mp-wp_genesis 547 */
mp-wp_genesis 548 function hide_errors() {
mp-wp_genesis 549 $show = $this->show_errors;
mp-wp_genesis 550 $this->show_errors = false;
mp-wp_genesis 551 return $show;
mp-wp_genesis 552 }
mp-wp_genesis 553
mp-wp_genesis 554 /**
mp-wp_genesis 555 * Whether to suppress database errors.
mp-wp_genesis 556 *
mp-wp_genesis 557 * @param unknown_type $suppress
mp-wp_genesis 558 * @return unknown
mp-wp_genesis 559 */
mp-wp_genesis 560 function suppress_errors( $suppress = true ) {
mp-wp_genesis 561 $errors = $this->suppress_errors;
mp-wp_genesis 562 $this->suppress_errors = $suppress;
mp-wp_genesis 563 return $errors;
mp-wp_genesis 564 }
mp-wp_genesis 565
mp-wp_genesis 566 /**
mp-wp_genesis 567 * Kill cached query results.
mp-wp_genesis 568 *
mp-wp_genesis 569 * @since 0.71
mp-wp_genesis 570 */
mp-wp_genesis 571 function flush() {
mp-wp_genesis 572 $this->last_result = array();
mp-wp_genesis 573 $this->col_info = null;
mp-wp_genesis 574 $this->last_query = null;
mp-wp_genesis 575 }
mp-wp_genesis 576
mp-wp_genesis 577 /**
mp-wp_genesis 578 * Perform a MySQL database query, using current database connection.
mp-wp_genesis 579 *
mp-wp_genesis 580 * More information can be found on the codex page.
mp-wp_genesis 581 *
mp-wp_genesis 582 * @since 0.71
mp-wp_genesis 583 *
mp-wp_genesis 584 * @param string $query
mp-wp_genesis 585 * @return unknown
mp-wp_genesis 586 */
mp-wp_genesis 587 function query($query) {
mp-wp_genesis 588 if ( ! $this->ready )
mp-wp_genesis 589 return false;
mp-wp_genesis 590
mp-wp_genesis 591 // filter the query, if filters are available
mp-wp_genesis 592 // NOTE: some queries are made before the plugins have been loaded, and thus cannot be filtered with this method
mp-wp_genesis 593 if ( function_exists('apply_filters') )
mp-wp_genesis 594 $query = apply_filters('query', $query);
mp-wp_genesis 595
mp-wp_genesis 596 // initialise return
mp-wp_genesis 597 $return_val = 0;
mp-wp_genesis 598 $this->flush();
mp-wp_genesis 599
mp-wp_genesis 600 // Log how the function was called
mp-wp_genesis 601 $this->func_call = "\$db->query(\"$query\")";
mp-wp_genesis 602
mp-wp_genesis 603 // Keep track of the last query for debug..
mp-wp_genesis 604 $this->last_query = $query;
mp-wp_genesis 605
mp-wp_genesis 606 // Perform the query via std mysql_query function..
mp-wp_genesis 607 if ( defined('SAVEQUERIES') && SAVEQUERIES )
mp-wp_genesis 608 $this->timer_start();
mp-wp_genesis 609
mp-wp_genesis 610 $this->result = @mysql_query($query, $this->dbh);
mp-wp_genesis 611 ++$this->num_queries;
mp-wp_genesis 612
mp-wp_genesis 613 if ( defined('SAVEQUERIES') && SAVEQUERIES )
mp-wp_genesis 614 $this->queries[] = array( $query, $this->timer_stop(), $this->get_caller() );
mp-wp_genesis 615
mp-wp_genesis 616 // If there is an error then take note of it..
mp-wp_genesis 617 if ( $this->last_error = mysql_error($this->dbh) ) {
mp-wp_genesis 618 $this->print_error();
mp-wp_genesis 619 return false;
mp-wp_genesis 620 }
mp-wp_genesis 621
mp-wp_genesis 622 if ( preg_match("/^\\s*(insert|delete|update|replace|alter) /i",$query) ) {
mp-wp_genesis 623 $this->rows_affected = mysql_affected_rows($this->dbh);
mp-wp_genesis 624 // Take note of the insert_id
mp-wp_genesis 625 if ( preg_match("/^\\s*(insert|replace) /i",$query) ) {
mp-wp_genesis 626 $this->insert_id = mysql_insert_id($this->dbh);
mp-wp_genesis 627 }
mp-wp_genesis 628 // Return number of rows affected
mp-wp_genesis 629 $return_val = $this->rows_affected;
mp-wp_genesis 630 } else {
mp-wp_genesis 631 $i = 0;
mp-wp_genesis 632 while ($i < @mysql_num_fields($this->result)) {
mp-wp_genesis 633 $this->col_info[$i] = @mysql_fetch_field($this->result);
mp-wp_genesis 634 $i++;
mp-wp_genesis 635 }
mp-wp_genesis 636 $num_rows = 0;
mp-wp_genesis 637 while ( $row = @mysql_fetch_object($this->result) ) {
mp-wp_genesis 638 $this->last_result[$num_rows] = $row;
mp-wp_genesis 639 $num_rows++;
mp-wp_genesis 640 }
mp-wp_genesis 641
mp-wp_genesis 642 @mysql_free_result($this->result);
mp-wp_genesis 643
mp-wp_genesis 644 // Log number of rows the query returned
mp-wp_genesis 645 $this->num_rows = $num_rows;
mp-wp_genesis 646
mp-wp_genesis 647 // Return number of rows selected
mp-wp_genesis 648 $return_val = $this->num_rows;
mp-wp_genesis 649 }
mp-wp_genesis 650
mp-wp_genesis 651 return $return_val;
mp-wp_genesis 652 }
mp-wp_genesis 653
mp-wp_genesis 654 /**
mp-wp_genesis 655 * Insert an array of data into a table.
mp-wp_genesis 656 *
mp-wp_genesis 657 * @since 2.5.0
mp-wp_genesis 658 *
mp-wp_genesis 659 * @param string $table WARNING: not sanitized!
mp-wp_genesis 660 * @param array $data Should not already be SQL-escaped
mp-wp_genesis 661 * @return mixed Results of $this->query()
mp-wp_genesis 662 */
mp-wp_genesis 663 function insert($table, $data) {
mp-wp_genesis 664 $data = add_magic_quotes($data);
mp-wp_genesis 665 $fields = array_keys($data);
mp-wp_genesis 666 return $this->query("INSERT INTO $table (`" . implode('`,`',$fields) . "`) VALUES ('".implode("','",$data)."')");
mp-wp_genesis 667 }
mp-wp_genesis 668
mp-wp_genesis 669 /**
mp-wp_genesis 670 * Update a row in the table with an array of data.
mp-wp_genesis 671 *
mp-wp_genesis 672 * @since 2.5.0
mp-wp_genesis 673 *
mp-wp_genesis 674 * @param string $table WARNING: not sanitized!
mp-wp_genesis 675 * @param array $data Should not already be SQL-escaped
mp-wp_genesis 676 * @param array $where A named array of WHERE column => value relationships. Multiple member pairs will be joined with ANDs. WARNING: the column names are not currently sanitized!
mp-wp_genesis 677 * @return mixed Results of $this->query()
mp-wp_genesis 678 */
mp-wp_genesis 679 function update($table, $data, $where){
mp-wp_genesis 680 $data = add_magic_quotes($data);
mp-wp_genesis 681 $bits = $wheres = array();
mp-wp_genesis 682 foreach ( (array) array_keys($data) as $k )
mp-wp_genesis 683 $bits[] = "`$k` = '$data[$k]'";
mp-wp_genesis 684
mp-wp_genesis 685 if ( is_array( $where ) )
mp-wp_genesis 686 foreach ( $where as $c => $v )
mp-wp_genesis 687 $wheres[] = "$c = '" . $this->escape( $v ) . "'";
mp-wp_genesis 688 else
mp-wp_genesis 689 return false;
mp-wp_genesis 690
mp-wp_genesis 691 return $this->query( "UPDATE $table SET " . implode( ', ', $bits ) . ' WHERE ' . implode( ' AND ', $wheres ) );
mp-wp_genesis 692 }
mp-wp_genesis 693
mp-wp_genesis 694 /**
mp-wp_genesis 695 * Retrieve one variable from the database.
mp-wp_genesis 696 *
mp-wp_genesis 697 * This combines the functionality of wpdb::get_row() and wpdb::get_col(),
mp-wp_genesis 698 * so both the column and row can be picked.
mp-wp_genesis 699 *
mp-wp_genesis 700 * It is possible to use this function without executing more queries. If
mp-wp_genesis 701 * you already made a query, you can set the $query to 'null' value and just
mp-wp_genesis 702 * retrieve either the column and row of the last query result.
mp-wp_genesis 703 *
mp-wp_genesis 704 * @since 0.71
mp-wp_genesis 705 *
mp-wp_genesis 706 * @param string $query Can be null as well, for caching
mp-wp_genesis 707 * @param int $x Column num to return
mp-wp_genesis 708 * @param int $y Row num to return
mp-wp_genesis 709 * @return mixed Database query results
mp-wp_genesis 710 */
mp-wp_genesis 711 function get_var($query=null, $x = 0, $y = 0) {
mp-wp_genesis 712 $this->func_call = "\$db->get_var(\"$query\",$x,$y)";
mp-wp_genesis 713 if ( $query )
mp-wp_genesis 714 $this->query($query);
mp-wp_genesis 715
mp-wp_genesis 716 // Extract var out of cached results based x,y vals
mp-wp_genesis 717 if ( !empty( $this->last_result[$y] ) ) {
mp-wp_genesis 718 $values = array_values(get_object_vars($this->last_result[$y]));
mp-wp_genesis 719 }
mp-wp_genesis 720
mp-wp_genesis 721 // If there is a value return it else return null
mp-wp_genesis 722 return (isset($values[$x]) && $values[$x]!=='') ? $values[$x] : null;
mp-wp_genesis 723 }
mp-wp_genesis 724
mp-wp_genesis 725 /**
mp-wp_genesis 726 * Retrieve one row from the database.
mp-wp_genesis 727 *
mp-wp_genesis 728 * @since 0.71
mp-wp_genesis 729 *
mp-wp_genesis 730 * @param string $query SQL query
mp-wp_genesis 731 * @param string $output ARRAY_A | ARRAY_N | OBJECT
mp-wp_genesis 732 * @param int $y Row num to return
mp-wp_genesis 733 * @return mixed Database query results
mp-wp_genesis 734 */
mp-wp_genesis 735 function get_row($query = null, $output = OBJECT, $y = 0) {
mp-wp_genesis 736 $this->func_call = "\$db->get_row(\"$query\",$output,$y)";
mp-wp_genesis 737 if ( $query )
mp-wp_genesis 738 $this->query($query);
mp-wp_genesis 739 else
mp-wp_genesis 740 return null;
mp-wp_genesis 741
mp-wp_genesis 742 if ( !isset($this->last_result[$y]) )
mp-wp_genesis 743 return null;
mp-wp_genesis 744
mp-wp_genesis 745 if ( $output == OBJECT ) {
mp-wp_genesis 746 return $this->last_result[$y] ? $this->last_result[$y] : null;
mp-wp_genesis 747 } elseif ( $output == ARRAY_A ) {
mp-wp_genesis 748 return $this->last_result[$y] ? get_object_vars($this->last_result[$y]) : null;
mp-wp_genesis 749 } elseif ( $output == ARRAY_N ) {
mp-wp_genesis 750 return $this->last_result[$y] ? array_values(get_object_vars($this->last_result[$y])) : null;
mp-wp_genesis 751 } else {
mp-wp_genesis 752 $this->print_error(/*WP_I18N_DB_GETROW_ERROR*/" \$db->get_row(string query, output type, int offset) -- Output type must be one of: OBJECT, ARRAY_A, ARRAY_N"/*/WP_I18N_DB_GETROW_ERROR*/);
mp-wp_genesis 753 }
mp-wp_genesis 754 }
mp-wp_genesis 755
mp-wp_genesis 756 /**
mp-wp_genesis 757 * Retrieve one column from the database.
mp-wp_genesis 758 *
mp-wp_genesis 759 * @since 0.71
mp-wp_genesis 760 *
mp-wp_genesis 761 * @param string $query Can be null as well, for caching
mp-wp_genesis 762 * @param int $x Col num to return. Starts from 0.
mp-wp_genesis 763 * @return array Column results
mp-wp_genesis 764 */
mp-wp_genesis 765 function get_col($query = null , $x = 0) {
mp-wp_genesis 766 if ( $query )
mp-wp_genesis 767 $this->query($query);
mp-wp_genesis 768
mp-wp_genesis 769 $new_array = array();
mp-wp_genesis 770 // Extract the column values
mp-wp_genesis 771 for ( $i=0; $i < count($this->last_result); $i++ ) {
mp-wp_genesis 772 $new_array[$i] = $this->get_var(null, $x, $i);
mp-wp_genesis 773 }
mp-wp_genesis 774 return $new_array;
mp-wp_genesis 775 }
mp-wp_genesis 776
mp-wp_genesis 777 /**
mp-wp_genesis 778 * Retrieve an entire result set from the database.
mp-wp_genesis 779 *
mp-wp_genesis 780 * @since 0.71
mp-wp_genesis 781 *
mp-wp_genesis 782 * @param string|null $query Can also be null to pull from the cache
mp-wp_genesis 783 * @param string $output ARRAY_A | ARRAY_N | OBJECT_K | OBJECT
mp-wp_genesis 784 * @return mixed Database query results
mp-wp_genesis 785 */
mp-wp_genesis 786 function get_results($query = null, $output = OBJECT) {
mp-wp_genesis 787 $this->func_call = "\$db->get_results(\"$query\", $output)";
mp-wp_genesis 788
mp-wp_genesis 789 if ( $query )
mp-wp_genesis 790 $this->query($query);
mp-wp_genesis 791 else
mp-wp_genesis 792 return null;
mp-wp_genesis 793
mp-wp_genesis 794 if ( $output == OBJECT ) {
mp-wp_genesis 795 // Return an integer-keyed array of row objects
mp-wp_genesis 796 return $this->last_result;
mp-wp_genesis 797 } elseif ( $output == OBJECT_K ) {
mp-wp_genesis 798 // Return an array of row objects with keys from column 1
mp-wp_genesis 799 // (Duplicates are discarded)
mp-wp_genesis 800 foreach ( $this->last_result as $row ) {
mp-wp_genesis 801 $key = array_shift( get_object_vars( $row ) );
mp-wp_genesis 802 if ( !isset( $new_array[ $key ] ) )
mp-wp_genesis 803 $new_array[ $key ] = $row;
mp-wp_genesis 804 }
mp-wp_genesis 805 return $new_array;
mp-wp_genesis 806 } elseif ( $output == ARRAY_A || $output == ARRAY_N ) {
mp-wp_genesis 807 // Return an integer-keyed array of...
mp-wp_genesis 808 if ( $this->last_result ) {
mp-wp_genesis 809 $i = 0;
mp-wp_genesis 810 foreach( (array) $this->last_result as $row ) {
mp-wp_genesis 811 if ( $output == ARRAY_N ) {
mp-wp_genesis 812 // ...integer-keyed row arrays
mp-wp_genesis 813 $new_array[$i] = array_values( get_object_vars( $row ) );
mp-wp_genesis 814 } else {
mp-wp_genesis 815 // ...column name-keyed row arrays
mp-wp_genesis 816 $new_array[$i] = get_object_vars( $row );
mp-wp_genesis 817 }
mp-wp_genesis 818 ++$i;
mp-wp_genesis 819 }
mp-wp_genesis 820 return $new_array;
mp-wp_genesis 821 }
mp-wp_genesis 822 }
mp-wp_genesis 823 }
mp-wp_genesis 824
mp-wp_genesis 825 /**
mp-wp_genesis 826 * Retrieve column metadata from the last query.
mp-wp_genesis 827 *
mp-wp_genesis 828 * @since 0.71
mp-wp_genesis 829 *
mp-wp_genesis 830 * @param string $info_type one of name, table, def, max_length, not_null, primary_key, multiple_key, unique_key, numeric, blob, type, unsigned, zerofill
mp-wp_genesis 831 * @param int $col_offset 0: col name. 1: which table the col's in. 2: col's max length. 3: if the col is numeric. 4: col's type
mp-wp_genesis 832 * @return mixed Column Results
mp-wp_genesis 833 */
mp-wp_genesis 834 function get_col_info($info_type = 'name', $col_offset = -1) {
mp-wp_genesis 835 if ( $this->col_info ) {
mp-wp_genesis 836 if ( $col_offset == -1 ) {
mp-wp_genesis 837 $i = 0;
mp-wp_genesis 838 foreach( (array) $this->col_info as $col ) {
mp-wp_genesis 839 $new_array[$i] = $col->{$info_type};
mp-wp_genesis 840 $i++;
mp-wp_genesis 841 }
mp-wp_genesis 842 return $new_array;
mp-wp_genesis 843 } else {
mp-wp_genesis 844 return $this->col_info[$col_offset]->{$info_type};
mp-wp_genesis 845 }
mp-wp_genesis 846 }
mp-wp_genesis 847 }
mp-wp_genesis 848
mp-wp_genesis 849 /**
mp-wp_genesis 850 * Starts the timer, for debugging purposes.
mp-wp_genesis 851 *
mp-wp_genesis 852 * @since 1.5.0
mp-wp_genesis 853 *
mp-wp_genesis 854 * @return bool Always returns true
mp-wp_genesis 855 */
mp-wp_genesis 856 function timer_start() {
mp-wp_genesis 857 $mtime = microtime();
mp-wp_genesis 858 $mtime = explode(' ', $mtime);
mp-wp_genesis 859 $this->time_start = $mtime[1] + $mtime[0];
mp-wp_genesis 860 return true;
mp-wp_genesis 861 }
mp-wp_genesis 862
mp-wp_genesis 863 /**
mp-wp_genesis 864 * Stops the debugging timer.
mp-wp_genesis 865 *
mp-wp_genesis 866 * @since 1.5.0
mp-wp_genesis 867 *
mp-wp_genesis 868 * @return int Total time spent on the query, in milliseconds
mp-wp_genesis 869 */
mp-wp_genesis 870 function timer_stop() {
mp-wp_genesis 871 $mtime = microtime();
mp-wp_genesis 872 $mtime = explode(' ', $mtime);
mp-wp_genesis 873 $time_end = $mtime[1] + $mtime[0];
mp-wp_genesis 874 $time_total = $time_end - $this->time_start;
mp-wp_genesis 875 return $time_total;
mp-wp_genesis 876 }
mp-wp_genesis 877
mp-wp_genesis 878 /**
mp-wp_genesis 879 * Wraps fatal errors in a nice header and footer and dies.
mp-wp_genesis 880 *
mp-wp_genesis 881 * @since 1.5.0
mp-wp_genesis 882 *
mp-wp_genesis 883 * @param string $message
mp-wp_genesis 884 * @return unknown
mp-wp_genesis 885 */
mp-wp_genesis 886 function bail($message) {
mp-wp_genesis 887 if ( !$this->show_errors ) {
mp-wp_genesis 888 if ( class_exists('WP_Error') )
mp-wp_genesis 889 $this->error = new WP_Error('500', $message);
mp-wp_genesis 890 else
mp-wp_genesis 891 $this->error = $message;
mp-wp_genesis 892 return false;
mp-wp_genesis 893 }
mp-wp_genesis 894 wp_die($message);
mp-wp_genesis 895 }
mp-wp_genesis 896
mp-wp_genesis 897 /**
mp-wp_genesis 898 * Whether or not MySQL database is minimal required version.
mp-wp_genesis 899 *
mp-wp_genesis 900 * @since 2.5.0
mp-wp_genesis 901 * @uses $wp_version
mp-wp_genesis 902 *
mp-wp_genesis 903 * @return WP_Error
mp-wp_genesis 904 */
mp-wp_genesis 905 function check_database_version()
mp-wp_genesis 906 {
mp-wp_genesis 907 global $wp_version;
mp-wp_genesis 908 // Make sure the server has MySQL 4.0
mp-wp_genesis 909 if ( version_compare($this->db_version(), '4.0.0', '<') )
mp-wp_genesis 910 return new WP_Error('database_version',sprintf(__('<strong>ERROR</strong>: WordPress %s requires MySQL 4.0.0 or higher'), $wp_version));
mp-wp_genesis 911 }
mp-wp_genesis 912
mp-wp_genesis 913 /**
mp-wp_genesis 914 * Whether of not the database version supports collation.
mp-wp_genesis 915 *
mp-wp_genesis 916 * Called when WordPress is generating the table scheme.
mp-wp_genesis 917 *
mp-wp_genesis 918 * @since 2.5.0
mp-wp_genesis 919 *
mp-wp_genesis 920 * @return bool True if collation is supported, false if version does not
mp-wp_genesis 921 */
mp-wp_genesis 922 function supports_collation()
mp-wp_genesis 923 {
mp-wp_genesis 924 return $this->has_cap( 'collation' );
mp-wp_genesis 925 }
mp-wp_genesis 926
mp-wp_genesis 927 /**
mp-wp_genesis 928 * Generic function to determine if a database supports a particular feature
mp-wp_genesis 929 * @param string $db_cap the feature
mp-wp_genesis 930 * @param false|string|resource $dbh_or_table the databaese (the current database, the database housing the specified table, or the database of the mysql resource)
mp-wp_genesis 931 * @return bool
mp-wp_genesis 932 */
mp-wp_genesis 933 function has_cap( $db_cap ) {
mp-wp_genesis 934 $version = $this->db_version();
mp-wp_genesis 935
mp-wp_genesis 936 switch ( strtolower( $db_cap ) ) :
mp-wp_genesis 937 case 'collation' : // @since 2.5.0
mp-wp_genesis 938 case 'group_concat' : // @since 2.7
mp-wp_genesis 939 case 'subqueries' : // @since 2.7
mp-wp_genesis 940 return version_compare($version, '4.1', '>=');
mp-wp_genesis 941 break;
mp-wp_genesis 942 endswitch;
mp-wp_genesis 943
mp-wp_genesis 944 return false;
mp-wp_genesis 945 }
mp-wp_genesis 946
mp-wp_genesis 947 /**
mp-wp_genesis 948 * Retrieve the name of the function that called wpdb.
mp-wp_genesis 949 *
mp-wp_genesis 950 * Requires PHP 4.3 and searches up the list of functions until it reaches
mp-wp_genesis 951 * the one that would most logically had called this method.
mp-wp_genesis 952 *
mp-wp_genesis 953 * @since 2.5.0
mp-wp_genesis 954 *
mp-wp_genesis 955 * @return string The name of the calling function
mp-wp_genesis 956 */
mp-wp_genesis 957 function get_caller() {
mp-wp_genesis 958 // requires PHP 4.3+
mp-wp_genesis 959 if ( !is_callable('debug_backtrace') )
mp-wp_genesis 960 return '';
mp-wp_genesis 961
mp-wp_genesis 962 $bt = debug_backtrace();
mp-wp_genesis 963 $caller = array();
mp-wp_genesis 964
mp-wp_genesis 965 $bt = array_reverse( $bt );
mp-wp_genesis 966 foreach ( (array) $bt as $call ) {
mp-wp_genesis 967 if ( @$call['class'] == __CLASS__ )
mp-wp_genesis 968 continue;
mp-wp_genesis 969 $function = $call['function'];
mp-wp_genesis 970 if ( isset( $call['class'] ) )
mp-wp_genesis 971 $function = $call['class'] . "->$function";
mp-wp_genesis 972 $caller[] = $function;
mp-wp_genesis 973 }
mp-wp_genesis 974 $caller = join( ', ', $caller );
mp-wp_genesis 975
mp-wp_genesis 976 return $caller;
mp-wp_genesis 977 }
mp-wp_genesis 978
mp-wp_genesis 979 /**
mp-wp_genesis 980 * The database version number
mp-wp_genesis 981 * @return false|string false on failure, version number on success
mp-wp_genesis 982 */
mp-wp_genesis 983 function db_version() {
mp-wp_genesis 984 return preg_replace('/[^0-9.].*/', '', mysql_get_server_info( $this->dbh ));
mp-wp_genesis 985 }
mp-wp_genesis 986 }
mp-wp_genesis 987
mp-wp_genesis 988 if ( ! isset($wpdb) ) {
mp-wp_genesis 989 /**
mp-wp_genesis 990 * WordPress Database Object, if it isn't set already in wp-content/db.php
mp-wp_genesis 991 * @global object $wpdb Creates a new wpdb object based on wp-config.php Constants for the database
mp-wp_genesis 992 * @since 0.71
mp-wp_genesis 993 */
mp-wp_genesis 994 $wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
mp-wp_genesis 995 }
mp-wp_genesis 996 ?>