web/wp-includes/wp-db.php
changeset 194 32102edaa81b
parent 136 bde1974c263b
child 204 09a1c134465b
equal deleted inserted replaced
193:2f6f6f7551ca 194:32102edaa81b
    10  */
    10  */
    11 
    11 
    12 /**
    12 /**
    13  * @since 0.71
    13  * @since 0.71
    14  */
    14  */
    15 define('EZSQL_VERSION', 'WP1.25');
    15 define( 'EZSQL_VERSION', 'WP1.25' );
    16 
    16 
    17 /**
    17 /**
    18  * @since 0.71
    18  * @since 0.71
    19  */
    19  */
    20 define('OBJECT', 'OBJECT', true);
    20 define( 'OBJECT', 'OBJECT', true );
    21 
    21 
    22 /**
    22 /**
    23  * @since {@internal Version Unknown}}
    23  * @since 2.5.0
    24  */
    24  */
    25 define('OBJECT_K', 'OBJECT_K', false);
    25 define( 'OBJECT_K', 'OBJECT_K' );
    26 
    26 
    27 /**
    27 /**
    28  * @since 0.71
    28  * @since 0.71
    29  */
    29  */
    30 define('ARRAY_A', 'ARRAY_A', false);
    30 define( 'ARRAY_A', 'ARRAY_A' );
    31 
    31 
    32 /**
    32 /**
    33  * @since 0.71
    33  * @since 0.71
    34  */
    34  */
    35 define('ARRAY_N', 'ARRAY_N', false);
    35 define( 'ARRAY_N', 'ARRAY_N' );
    36 
    36 
    37 /**
    37 /**
    38  * WordPress Database Access Abstraction Object
    38  * WordPress Database Access Abstraction Object
    39  *
    39  *
    40  * It is possible to replace this class with your own
    40  * It is possible to replace this class with your own
    41  * by setting the $wpdb global variable in wp-content/db.php
    41  * by setting the $wpdb global variable in wp-content/db.php
    42  * file with your class. You can name it wpdb also, since
    42  * file to your class. The wpdb class will still be included,
    43  * this file will not be included, if the other file is
    43  * so you can extend it or simply use your own.
    44  * available.
       
    45  *
    44  *
    46  * @link http://codex.wordpress.org/Function_Reference/wpdb_Class
    45  * @link http://codex.wordpress.org/Function_Reference/wpdb_Class
    47  *
    46  *
    48  * @package WordPress
    47  * @package WordPress
    49  * @subpackage Database
    48  * @subpackage Database
    50  * @since 0.71
    49  * @since 0.71
    51  * @final
       
    52  */
    50  */
    53 class wpdb {
    51 class wpdb {
    54 
    52 
    55 	/**
    53 	/**
    56 	 * Whether to show SQL/DB errors
    54 	 * Whether to show SQL/DB errors
    63 
    61 
    64 	/**
    62 	/**
    65 	 * Whether to suppress errors during the DB bootstrapping.
    63 	 * Whether to suppress errors during the DB bootstrapping.
    66 	 *
    64 	 *
    67 	 * @access private
    65 	 * @access private
    68 	 * @since {@internal Version Unknown}}
    66 	 * @since 2.5.0
    69 	 * @var bool
    67 	 * @var bool
    70 	 */
    68 	 */
    71 	var $suppress_errors = false;
    69 	var $suppress_errors = false;
    72 
    70 
    73 	/**
    71 	/**
    74 	 * The last error during query.
    72 	 * The last error during query.
    75 	 *
    73 	 *
    76 	 * @since {@internal Version Unknown}}
    74 	 * @since 2.5.0
    77 	 * @var string
    75 	 * @var string
    78 	 */
    76 	 */
    79 	var $last_error = '';
    77 	var $last_error = '';
    80 
    78 
    81 	/**
    79 	/**
    86 	 * @var int
    84 	 * @var int
    87 	 */
    85 	 */
    88 	var $num_queries = 0;
    86 	var $num_queries = 0;
    89 
    87 
    90 	/**
    88 	/**
       
    89 	 * Count of rows returned by previous query
       
    90 	 *
       
    91 	 * @since 1.2.0
       
    92 	 * @access private
       
    93 	 * @var int
       
    94 	 */
       
    95 	var $num_rows = 0;
       
    96 
       
    97 	/**
       
    98 	 * Count of affected rows by previous query
       
    99 	 *
       
   100 	 * @since 0.71
       
   101 	 * @access private
       
   102 	 * @var int
       
   103 	 */
       
   104 	var $rows_affected = 0;
       
   105 
       
   106 	/**
       
   107 	 * The ID generated for an AUTO_INCREMENT column by the previous query (usually INSERT).
       
   108 	 *
       
   109 	 * @since 0.71
       
   110 	 * @access public
       
   111 	 * @var int
       
   112 	 */
       
   113 	var $insert_id = 0;
       
   114 
       
   115 	/**
    91 	 * Saved result of the last query made
   116 	 * Saved result of the last query made
    92 	 *
   117 	 *
    93 	 * @since 1.2.0
   118 	 * @since 1.2.0
    94 	 * @access private
   119 	 * @access private
    95 	 * @var array
   120 	 * @var array
    96 	 */
   121 	 */
    97 	var $last_query;
   122 	var $last_query;
       
   123 
       
   124 	/**
       
   125 	 * Results of the last query made
       
   126 	 *
       
   127 	 * @since 1.0.0
       
   128 	 * @access private
       
   129 	 * @var array|null
       
   130 	 */
       
   131 	var $last_result;
    98 
   132 
    99 	/**
   133 	/**
   100 	 * Saved info on the table column
   134 	 * Saved info on the table column
   101 	 *
   135 	 *
   102 	 * @since 1.2.0
   136 	 * @since 1.2.0
   135 	 * @var bool
   169 	 * @var bool
   136 	 */
   170 	 */
   137 	var $ready = false;
   171 	var $ready = false;
   138 
   172 
   139 	/**
   173 	/**
       
   174 	 * {@internal Missing Description}}
       
   175 	 *
       
   176 	 * @since 3.0.0
       
   177 	 * @access public
       
   178 	 * @var int
       
   179 	 */
       
   180 	var $blogid = 0;
       
   181 
       
   182 	/**
       
   183 	 * {@internal Missing Description}}
       
   184 	 *
       
   185 	 * @since 3.0.0
       
   186 	 * @access public
       
   187 	 * @var int
       
   188 	 */
       
   189 	var $siteid = 0;
       
   190 
       
   191 	/**
       
   192 	 * List of WordPress per-blog tables
       
   193 	 *
       
   194 	 * @since 2.5.0
       
   195 	 * @access private
       
   196 	 * @see wpdb::tables()
       
   197 	 * @var array
       
   198 	 */
       
   199 	var $tables = array( 'posts', 'comments', 'links', 'options', 'postmeta',
       
   200 		'terms', 'term_taxonomy', 'term_relationships', 'commentmeta' );
       
   201 
       
   202 	/**
       
   203 	 * List of deprecated WordPress tables
       
   204 	 *
       
   205 	 * categories, post2cat, and link2cat were deprecated in 2.3.0, db version 5539
       
   206 	 *
       
   207 	 * @since 2.9.0
       
   208 	 * @access private
       
   209 	 * @see wpdb::tables()
       
   210 	 * @var array
       
   211 	 */
       
   212 	var $old_tables = array( 'categories', 'post2cat', 'link2cat' );
       
   213 
       
   214 	/**
       
   215 	 * List of WordPress global tables
       
   216 	 *
       
   217 	 * @since 3.0.0
       
   218 	 * @access private
       
   219 	 * @see wpdb::tables()
       
   220 	 * @var array
       
   221 	 */
       
   222 	var $global_tables = array( 'users', 'usermeta' );
       
   223 
       
   224 	/**
       
   225 	 * List of Multisite global tables
       
   226 	 *
       
   227 	 * @since 3.0.0
       
   228 	 * @access private
       
   229 	 * @see wpdb::tables()
       
   230 	 * @var array
       
   231 	 */
       
   232 	var $ms_global_tables = array( 'blogs', 'signups', 'site', 'sitemeta',
       
   233 		'sitecategories', 'registration_log', 'blog_versions' );
       
   234 
       
   235 	/**
       
   236 	 * WordPress Comments table
       
   237 	 *
       
   238 	 * @since 1.5.0
       
   239 	 * @access public
       
   240 	 * @var string
       
   241 	 */
       
   242 	var $comments;
       
   243 
       
   244 	/**
       
   245 	 * WordPress Comment Metadata table
       
   246 	 *
       
   247 	 * @since 2.9.0
       
   248 	 * @access public
       
   249 	 * @var string
       
   250 	 */
       
   251 	var $commentmeta;
       
   252 
       
   253 	/**
       
   254 	 * WordPress Links table
       
   255 	 *
       
   256 	 * @since 1.5.0
       
   257 	 * @access public
       
   258 	 * @var string
       
   259 	 */
       
   260 	var $links;
       
   261 
       
   262 	/**
       
   263 	 * WordPress Options table
       
   264 	 *
       
   265 	 * @since 1.5.0
       
   266 	 * @access public
       
   267 	 * @var string
       
   268 	 */
       
   269 	var $options;
       
   270 
       
   271 	/**
       
   272 	 * WordPress Post Metadata table
       
   273 	 *
       
   274 	 * @since 1.5.0
       
   275 	 * @access public
       
   276 	 * @var string
       
   277 	 */
       
   278 	var $postmeta;
       
   279 
       
   280 	/**
   140 	 * WordPress Posts table
   281 	 * WordPress Posts table
   141 	 *
   282 	 *
   142 	 * @since 1.5.0
   283 	 * @since 1.5.0
   143 	 * @access public
   284 	 * @access public
   144 	 * @var string
   285 	 * @var string
   145 	 */
   286 	 */
   146 	var $posts;
   287 	var $posts;
   147 
   288 
   148 	/**
   289 	/**
       
   290 	 * WordPress Terms table
       
   291 	 *
       
   292 	 * @since 2.3.0
       
   293 	 * @access public
       
   294 	 * @var string
       
   295 	 */
       
   296 	var $terms;
       
   297 
       
   298 	/**
       
   299 	 * WordPress Term Relationships table
       
   300 	 *
       
   301 	 * @since 2.3.0
       
   302 	 * @access public
       
   303 	 * @var string
       
   304 	 */
       
   305 	var $term_relationships;
       
   306 
       
   307 	/**
       
   308 	 * WordPress Term Taxonomy table
       
   309 	 *
       
   310 	 * @since 2.3.0
       
   311 	 * @access public
       
   312 	 * @var string
       
   313 	 */
       
   314 	var $term_taxonomy;
       
   315 
       
   316 	/*
       
   317 	 * Global and Multisite tables
       
   318 	 */
       
   319 
       
   320 	/**
       
   321 	 * WordPress User Metadata table
       
   322 	 *
       
   323 	 * @since 2.3.0
       
   324 	 * @access public
       
   325 	 * @var string
       
   326 	 */
       
   327 	var $usermeta;
       
   328 
       
   329 	/**
   149 	 * WordPress Users table
   330 	 * WordPress Users table
   150 	 *
   331 	 *
   151 	 * @since 1.5.0
   332 	 * @since 1.5.0
   152 	 * @access public
   333 	 * @access public
   153 	 * @var string
   334 	 * @var string
   154 	 */
   335 	 */
   155 	var $users;
   336 	var $users;
   156 
   337 
   157 	/**
   338 	/**
   158 	 * WordPress Categories table
   339 	 * Multisite Blogs table
   159 	 *
   340 	 *
   160 	 * @since 1.5.0
   341 	 * @since 3.0.0
   161 	 * @access public
   342 	 * @access public
   162 	 * @var string
   343 	 * @var string
   163 	 */
   344 	 */
   164 	var $categories;
   345 	var $blogs;
   165 
   346 
   166 	/**
   347 	/**
   167 	 * WordPress Post to Category table
   348 	 * Multisite Blog Versions table
   168 	 *
   349 	 *
   169 	 * @since 1.5.0
   350 	 * @since 3.0.0
   170 	 * @access public
   351 	 * @access public
   171 	 * @var string
   352 	 * @var string
   172 	 */
   353 	 */
   173 	var $post2cat;
   354 	var $blog_versions;
   174 
   355 
   175 	/**
   356 	/**
   176 	 * WordPress Comments table
   357 	 * Multisite Registration Log table
   177 	 *
   358 	 *
   178 	 * @since 1.5.0
   359 	 * @since 3.0.0
   179 	 * @access public
   360 	 * @access public
   180 	 * @var string
   361 	 * @var string
   181 	 */
   362 	 */
   182 	var $comments;
   363 	var $registration_log;
   183 
   364 
   184 	/**
   365 	/**
   185 	 * WordPress Links table
   366 	 * Multisite Signups table
   186 	 *
   367 	 *
   187 	 * @since 1.5.0
   368 	 * @since 3.0.0
   188 	 * @access public
   369 	 * @access public
   189 	 * @var string
   370 	 * @var string
   190 	 */
   371 	 */
   191 	var $links;
   372 	var $signups;
   192 
   373 
   193 	/**
   374 	/**
   194 	 * WordPress Options table
   375 	 * Multisite Sites table
   195 	 *
   376 	 *
   196 	 * @since 1.5.0
   377 	 * @since 3.0.0
   197 	 * @access public
   378 	 * @access public
   198 	 * @var string
   379 	 * @var string
   199 	 */
   380 	 */
   200 	var $options;
   381 	var $site;
   201 
   382 
   202 	/**
   383 	/**
   203 	 * WordPress Post Metadata table
   384 	 * Multisite Sitewide Terms table
   204 	 *
   385 	 *
   205 	 * @since {@internal Version Unknown}}
   386 	 * @since 3.0.0
   206 	 * @access public
   387 	 * @access public
   207 	 * @var string
   388 	 * @var string
   208 	 */
   389 	 */
   209 	var $postmeta;
   390 	var $sitecategories;
   210 
   391 
   211 	/**
   392 	/**
   212 	 * WordPress Comment Metadata table
   393 	 * Multisite Site Metadata table
   213 	 *
   394 	 *
   214 	 * @since 2.9
   395 	 * @since 3.0.0
   215 	 * @access public
   396 	 * @access public
   216 	 * @var string
   397 	 * @var string
   217 	 */
   398 	 */
   218 	var $commentmeta;
   399 	var $sitemeta;
   219 
   400 
   220 	/**
   401 	/**
   221 	 * WordPress User Metadata table
   402 	 * Format specifiers for DB columns. Columns not listed here default to %s. Initialized during WP load.
   222 	 *
   403 	 *
   223 	 * @since 2.3.0
   404 	 * Keys are column names, values are format types: 'ID' => '%d'
   224 	 * @access public
   405 	 *
   225 	 * @var string
   406 	 * @since 2.8.0
   226 	 */
   407 	 * @see wpdb::prepare()
   227 	var $usermeta;
   408 	 * @see wpdb::insert()
   228 
   409 	 * @see wpdb::update()
   229 	/**
   410 	 * @see wpdb::delete()
   230 	 * WordPress Terms table
   411 	 * @see wp_set_wpdb_vars()
   231 	 *
   412 	 * @access public
   232 	 * @since 2.3.0
       
   233 	 * @access public
       
   234 	 * @var string
       
   235 	 */
       
   236 	var $terms;
       
   237 
       
   238 	/**
       
   239 	 * WordPress Term Taxonomy table
       
   240 	 *
       
   241 	 * @since 2.3.0
       
   242 	 * @access public
       
   243 	 * @var string
       
   244 	 */
       
   245 	var $term_taxonomy;
       
   246 
       
   247 	/**
       
   248 	 * WordPress Term Relationships table
       
   249 	 *
       
   250 	 * @since 2.3.0
       
   251 	 * @access public
       
   252 	 * @var string
       
   253 	 */
       
   254 	var $term_relationships;
       
   255 
       
   256 	/**
       
   257 	 * List of WordPress tables
       
   258 	 *
       
   259 	 * @since {@internal Version Unknown}}
       
   260 	 * @access private
       
   261 	 * @var array
   413 	 * @var array
   262 	 */
   414 	 */
   263 	var $tables = array('users', 'usermeta', 'posts', 'categories', 'post2cat', 'comments', 'links', 'link2cat', 'options',
   415 	var $field_types = array();
   264 			'postmeta', 'terms', 'term_taxonomy', 'term_relationships', 'commentmeta');
   416 
   265 
   417 	/**
   266 	/**
   418 	 * Database table columns charset
   267 	 * List of deprecated WordPress tables
   419 	 *
       
   420 	 * @since 2.2.0
       
   421 	 * @access public
       
   422 	 * @var string
       
   423 	 */
       
   424 	var $charset;
       
   425 
       
   426 	/**
       
   427 	 * Database table columns collate
       
   428 	 *
       
   429 	 * @since 2.2.0
       
   430 	 * @access public
       
   431 	 * @var string
       
   432 	 */
       
   433 	var $collate;
       
   434 
       
   435 	/**
       
   436 	 * Whether to use mysql_real_escape_string
       
   437 	 *
       
   438 	 * @since 2.8.0
       
   439 	 * @access public
       
   440 	 * @var bool
       
   441 	 */
       
   442 	var $real_escape = false;
       
   443 
       
   444 	/**
       
   445 	 * Database Username
   268 	 *
   446 	 *
   269 	 * @since 2.9.0
   447 	 * @since 2.9.0
   270 	 * @access private
   448 	 * @access private
   271 	 * @var array
   449 	 * @var string
   272 	 */
   450 	 */
   273 	var $old_tables = array('categories', 'post2cat', 'link2cat');
   451 	var $dbuser;
   274 
   452 
   275 
   453 	/**
   276 	/**
   454 	 * A textual description of the last query/get_row/get_var call
   277 	 * Format specifiers for DB columns. Columns not listed here default to %s.  Initialized in wp-settings.php.
   455 	 *
   278 	 *
   456 	 * @since 3.0.0
   279 	 * Keys are colmn names, values are format types: 'ID' => '%d'
   457 	 * @access public
   280 	 *
   458 	 * @var string
   281 	 * @since 2.8.0
   459 	 */
   282 	 * @see wpdb:prepare()
   460 	var $func_call;
   283 	 * @see wpdb:insert()
   461 
   284 	 * @see wpdb:update()
   462 	/**
   285 	 * @access public
   463 	 * Whether MySQL is used as the database engine.
   286 	 * @war array
   464 	 *
   287 	 */
   465 	 * Set in WPDB::db_connect() to true, by default. This is used when checking
   288 	var $field_types = array();
   466 	 * against the required MySQL version for WordPress. Normally, a replacement
   289 
   467 	 * database drop-in (db.php) will skip these checks, but setting this to true
   290 	/**
   468 	 * will force the checks to occur.
   291 	 * Database table columns charset
   469 	 *
   292 	 *
   470 	 * @since 3.3.0
   293 	 * @since 2.2.0
       
   294 	 * @access public
       
   295 	 * @var string
       
   296 	 */
       
   297 	var $charset;
       
   298 
       
   299 	/**
       
   300 	 * Database table columns collate
       
   301 	 *
       
   302 	 * @since 2.2.0
       
   303 	 * @access public
       
   304 	 * @var string
       
   305 	 */
       
   306 	var $collate;
       
   307 
       
   308 	/**
       
   309 	 * Whether to use mysql_real_escape_string
       
   310 	 *
       
   311 	 * @since 2.8.0
       
   312 	 * @access public
   471 	 * @access public
   313 	 * @var bool
   472 	 * @var bool
   314 	 */
   473 	 */
   315 	var $real_escape = false;
   474 	public $is_mysql = null;
   316 
       
   317 	/**
       
   318 	 * Database Username
       
   319 	 *
       
   320 	 * @since 2.9.0
       
   321 	 * @access private
       
   322 	 * @var string
       
   323 	 */
       
   324 	var $dbuser;
       
   325 
   475 
   326 	/**
   476 	/**
   327 	 * Connects to the database server and selects a database
   477 	 * Connects to the database server and selects a database
   328 	 *
   478 	 *
   329 	 * PHP4 compatibility layer for calling the PHP5 constructor.
   479 	 * PHP5 style constructor for compatibility with PHP5. Does
   330 	 *
   480 	 * the actual setting up of the class properties and connection
   331 	 * @uses wpdb::__construct() Passes parameters and returns result
   481 	 * to the database.
   332 	 * @since 0.71
   482 	 *
       
   483 	 * @link http://core.trac.wordpress.org/ticket/3354
       
   484 	 * @since 2.0.8
   333 	 *
   485 	 *
   334 	 * @param string $dbuser MySQL database user
   486 	 * @param string $dbuser MySQL database user
   335 	 * @param string $dbpassword MySQL database password
   487 	 * @param string $dbpassword MySQL database password
   336 	 * @param string $dbname MySQL database name
   488 	 * @param string $dbname MySQL database name
   337 	 * @param string $dbhost MySQL database host
   489 	 * @param string $dbhost MySQL database host
   338 	 */
   490 	 */
   339 	function wpdb($dbuser, $dbpassword, $dbname, $dbhost) {
   491 	function __construct( $dbuser, $dbpassword, $dbname, $dbhost ) {
   340 		return $this->__construct($dbuser, $dbpassword, $dbname, $dbhost);
   492 		register_shutdown_function( array( &$this, '__destruct' ) );
   341 	}
       
   342 
       
   343 	/**
       
   344 	 * Connects to the database server and selects a database
       
   345 	 *
       
   346 	 * PHP5 style constructor for compatibility with PHP5. Does
       
   347 	 * the actual setting up of the class properties and connection
       
   348 	 * to the database.
       
   349 	 *
       
   350 	 * @since 2.0.8
       
   351 	 *
       
   352 	 * @param string $dbuser MySQL database user
       
   353 	 * @param string $dbpassword MySQL database password
       
   354 	 * @param string $dbname MySQL database name
       
   355 	 * @param string $dbhost MySQL database host
       
   356 	 */
       
   357 	function __construct($dbuser, $dbpassword, $dbname, $dbhost) {
       
   358 		register_shutdown_function(array(&$this, "__destruct"));
       
   359 
   493 
   360 		if ( WP_DEBUG )
   494 		if ( WP_DEBUG )
   361 			$this->show_errors();
   495 			$this->show_errors();
   362 
   496 
   363 		if ( defined('DB_CHARSET') )
   497 		$this->init_charset();
       
   498 
       
   499 		$this->dbuser = $dbuser;
       
   500 		$this->dbpassword = $dbpassword;
       
   501 		$this->dbname = $dbname;
       
   502 		$this->dbhost = $dbhost;
       
   503 
       
   504 		$this->db_connect();
       
   505 	}
       
   506 
       
   507 	/**
       
   508 	 * PHP5 style destructor and will run when database object is destroyed.
       
   509 	 *
       
   510 	 * @see wpdb::__construct()
       
   511 	 * @since 2.0.8
       
   512 	 * @return bool true
       
   513 	 */
       
   514 	function __destruct() {
       
   515 		return true;
       
   516 	}
       
   517 
       
   518 	/**
       
   519 	 * Set $this->charset and $this->collate
       
   520 	 *
       
   521 	 * @since 3.1.0
       
   522 	 */
       
   523 	function init_charset() {
       
   524 		if ( function_exists('is_multisite') && is_multisite() ) {
       
   525 			$this->charset = 'utf8';
       
   526 			if ( defined( 'DB_COLLATE' ) && DB_COLLATE )
       
   527 				$this->collate = DB_COLLATE;
       
   528 			else
       
   529 				$this->collate = 'utf8_general_ci';
       
   530 		} elseif ( defined( 'DB_COLLATE' ) ) {
       
   531 			$this->collate = DB_COLLATE;
       
   532 		}
       
   533 
       
   534 		if ( defined( 'DB_CHARSET' ) )
   364 			$this->charset = DB_CHARSET;
   535 			$this->charset = DB_CHARSET;
   365 
   536 	}
   366 		if ( defined('DB_COLLATE') )
   537 
   367 			$this->collate = DB_COLLATE;
   538 	/**
   368 
   539 	 * Sets the connection's character set.
   369 		$this->dbuser = $dbuser;
   540 	 *
   370 
   541 	 * @since 3.1.0
   371 		$this->dbh = @mysql_connect($dbhost, $dbuser, $dbpassword, true);
   542 	 *
   372 		if (!$this->dbh) {
   543 	 * @param resource $dbh     The resource given by mysql_connect
   373 			$this->bail(sprintf(/*WP_I18N_DB_CONN_ERROR*/'
   544 	 * @param string   $charset The character set (optional)
   374 <h1>Erreur lors de l&rsquo;établissement de la connexion &agrave; la base de données</h1>
   545 	 * @param string   $collate The collation (optional)
   375 <p>Cela signifie soit que l&rsquo;identifiant et/ou le mot de passe indiqués dans votre fichier <code>wp-config.php</code> sont incorrects, ou que le serveur de base de données à l&rsquo;adresse <code>%s</code> est inaccessible - ce qui implique que le serveur de base de données de votre hébergeur est sans doute défaillant.</p>
   546 	 */
   376 <ul>
   547 	function set_charset($dbh, $charset = null, $collate = null) {
   377 	<li>Êtes-vous certain(e) d&rsquo;avoir correctement indiqué votre identifiant et votre mot de passe&nbsp;?</li>
   548 		if ( !isset($charset) )
   378 	<li>Êtes-vous certain(e) d&rsquo;avoir entré le bon serveur de base de données&nbsp;?</li>
   549 			$charset = $this->charset;
   379 	<li>Êtes-vous certain(e) que le serveur de base de données fonctionne correctement&nbsp;?</li>
   550 		if ( !isset($collate) )
   380 </ul>
   551 			$collate = $this->collate;
   381 <p>Si vous n&rsquo;êtes pas sûr(e) de bien comprendre les mots de cette liste, vous devriez sans doute prendre contact avec votre hébergeur. Si malgré cela cette erreur s&rsquo;affiche toujours, indiquez votre problème au <a href=\'http://www.wordpress-fr.net/support/\'>forum d&rsquo;entraide en français</a>.</p>
   552 		if ( $this->has_cap( 'collation', $dbh ) && !empty( $charset ) ) {
   382 '/*/WP_I18N_DB_CONN_ERROR*/, $dbhost), 'db_connect_fail');
   553 			if ( function_exists( 'mysql_set_charset' ) && $this->has_cap( 'set_charset', $dbh ) ) {
   383 			return;
   554 				mysql_set_charset( $charset, $dbh );
   384 		}
       
   385 
       
   386 		$this->ready = true;
       
   387 
       
   388 		if ( $this->has_cap( 'collation' ) && !empty($this->charset) ) {
       
   389 			if ( function_exists('mysql_set_charset') ) {
       
   390 				mysql_set_charset($this->charset, $this->dbh);
       
   391 				$this->real_escape = true;
   555 				$this->real_escape = true;
   392 			} else {
   556 			} else {
   393 				$collation_query = "SET NAMES '{$this->charset}'";
   557 				$query = $this->prepare( 'SET NAMES %s', $charset );
   394 				if ( !empty($this->collate) )
   558 				if ( ! empty( $collate ) )
   395 					$collation_query .= " COLLATE '{$this->collate}'";
   559 					$query .= $this->prepare( ' COLLATE %s', $collate );
   396 				$this->query($collation_query);
   560 				mysql_query( $query, $dbh );
   397 			}
   561 			}
   398 		}
   562 		}
   399 
       
   400 		$this->select($dbname);
       
   401 	}
       
   402 
       
   403 	/**
       
   404 	 * PHP5 style destructor and will run when database object is destroyed.
       
   405 	 *
       
   406 	 * @since 2.0.8
       
   407 	 *
       
   408 	 * @return bool Always true
       
   409 	 */
       
   410 	function __destruct() {
       
   411 		return true;
       
   412 	}
   563 	}
   413 
   564 
   414 	/**
   565 	/**
   415 	 * Sets the table prefix for the WordPress tables.
   566 	 * Sets the table prefix for the WordPress tables.
   416 	 *
   567 	 *
       
   568 	 * @since 2.5.0
       
   569 	 *
       
   570 	 * @param string $prefix Alphanumeric name for the new prefix.
       
   571 	 * @param bool $set_table_names Optional. Whether the table names, e.g. wpdb::$posts, should be updated or not.
       
   572 	 * @return string|WP_Error Old prefix or WP_Error on error
       
   573 	 */
       
   574 	function set_prefix( $prefix, $set_table_names = true ) {
       
   575 
       
   576 		if ( preg_match( '|[^a-z0-9_]|i', $prefix ) )
       
   577 			return new WP_Error('invalid_db_prefix', 'Invalid database prefix' );
       
   578 
       
   579 		$old_prefix = is_multisite() ? '' : $prefix;
       
   580 
       
   581 		if ( isset( $this->base_prefix ) )
       
   582 			$old_prefix = $this->base_prefix;
       
   583 
       
   584 		$this->base_prefix = $prefix;
       
   585 
       
   586 		if ( $set_table_names ) {
       
   587 			foreach ( $this->tables( 'global' ) as $table => $prefixed_table )
       
   588 				$this->$table = $prefixed_table;
       
   589 
       
   590 			if ( is_multisite() && empty( $this->blogid ) )
       
   591 				return $old_prefix;
       
   592 
       
   593 			$this->prefix = $this->get_blog_prefix();
       
   594 
       
   595 			foreach ( $this->tables( 'blog' ) as $table => $prefixed_table )
       
   596 				$this->$table = $prefixed_table;
       
   597 
       
   598 			foreach ( $this->tables( 'old' ) as $table => $prefixed_table )
       
   599 				$this->$table = $prefixed_table;
       
   600 		}
       
   601 		return $old_prefix;
       
   602 	}
       
   603 
       
   604 	/**
       
   605 	 * Sets blog id.
       
   606 	 *
       
   607 	 * @since 3.0.0
       
   608 	 * @access public
       
   609 	 * @param int $blog_id
       
   610 	 * @param int $site_id Optional.
       
   611 	 * @return string previous blog id
       
   612 	 */
       
   613 	function set_blog_id( $blog_id, $site_id = 0 ) {
       
   614 		if ( ! empty( $site_id ) )
       
   615 			$this->siteid = $site_id;
       
   616 
       
   617 		$old_blog_id  = $this->blogid;
       
   618 		$this->blogid = $blog_id;
       
   619 
       
   620 		$this->prefix = $this->get_blog_prefix();
       
   621 
       
   622 		foreach ( $this->tables( 'blog' ) as $table => $prefixed_table )
       
   623 			$this->$table = $prefixed_table;
       
   624 
       
   625 		foreach ( $this->tables( 'old' ) as $table => $prefixed_table )
       
   626 			$this->$table = $prefixed_table;
       
   627 
       
   628 		return $old_blog_id;
       
   629 	}
       
   630 
       
   631 	/**
       
   632 	 * Gets blog prefix.
       
   633 	 *
       
   634 	 * @uses is_multisite()
       
   635 	 * @since 3.0.0
       
   636 	 * @param int $blog_id Optional.
       
   637 	 * @return string Blog prefix.
       
   638 	 */
       
   639 	function get_blog_prefix( $blog_id = null ) {
       
   640 		if ( is_multisite() ) {
       
   641 			if ( null === $blog_id )
       
   642 				$blog_id = $this->blogid;
       
   643 			$blog_id = (int) $blog_id;
       
   644 			if ( defined( 'MULTISITE' ) && ( 0 == $blog_id || 1 == $blog_id ) )
       
   645 				return $this->base_prefix;
       
   646 			else
       
   647 				return $this->base_prefix . $blog_id . '_';
       
   648 		} else {
       
   649 			return $this->base_prefix;
       
   650 		}
       
   651 	}
       
   652 
       
   653 	/**
       
   654 	 * Returns an array of WordPress tables.
       
   655 	 *
   417 	 * Also allows for the CUSTOM_USER_TABLE and CUSTOM_USER_META_TABLE to
   656 	 * Also allows for the CUSTOM_USER_TABLE and CUSTOM_USER_META_TABLE to
   418 	 * override the WordPress users and usersmeta tables that would otherwise be determined by the $prefix.
   657 	 * override the WordPress users and usermeta tables that would otherwise
   419 	 *
   658 	 * be determined by the prefix.
   420 	 * @since 2.5.0
   659 	 *
   421 	 *
   660 	 * The scope argument can take one of the following:
   422 	 * @param string $prefix Alphanumeric name for the new prefix.
   661 	 *
   423 	 * @return string|WP_Error Old prefix or WP_Error on error
   662 	 * 'all' - returns 'all' and 'global' tables. No old tables are returned.
   424 	 */
   663 	 * 'blog' - returns the blog-level tables for the queried blog.
   425 	function set_prefix($prefix) {
   664 	 * 'global' - returns the global tables for the installation, returning multisite tables only if running multisite.
   426 
   665 	 * 'ms_global' - returns the multisite global tables, regardless if current installation is multisite.
   427 		if ( preg_match('|[^a-z0-9_]|i', $prefix) )
   666 	 * 'old' - returns tables which are deprecated.
   428 			return new WP_Error('invalid_db_prefix', /*WP_I18N_DB_BAD_PREFIX*/'Préfixe de la base de données invalide'/*/WP_I18N_DB_BAD_PREFIX*/);
   667 	 *
   429 
   668 	 * @since 3.0.0
   430 		$old_prefix = $this->prefix;
   669 	 * @uses wpdb::$tables
   431 		$this->prefix = $prefix;
   670 	 * @uses wpdb::$old_tables
   432 
   671 	 * @uses wpdb::$global_tables
   433 		foreach ( (array) $this->tables as $table )
   672 	 * @uses wpdb::$ms_global_tables
   434 			$this->$table = $this->prefix . $table;
   673 	 * @uses is_multisite()
   435 
   674 	 *
   436 		if ( defined('CUSTOM_USER_TABLE') )
   675 	 * @param string $scope Optional. Can be all, global, ms_global, blog, or old tables. Defaults to all.
   437 			$this->users = CUSTOM_USER_TABLE;
   676 	 * @param bool $prefix Optional. Whether to include table prefixes. Default true. If blog
   438 
   677 	 * 	prefix is requested, then the custom users and usermeta tables will be mapped.
   439 		if ( defined('CUSTOM_USER_META_TABLE') )
   678 	 * @param int $blog_id Optional. The blog_id to prefix. Defaults to wpdb::$blogid. Used only when prefix is requested.
   440 			$this->usermeta = CUSTOM_USER_META_TABLE;
   679 	 * @return array Table names. When a prefix is requested, the key is the unprefixed table name.
   441 
   680 	 */
   442 		return $old_prefix;
   681 	function tables( $scope = 'all', $prefix = true, $blog_id = 0 ) {
       
   682 		switch ( $scope ) {
       
   683 			case 'all' :
       
   684 				$tables = array_merge( $this->global_tables, $this->tables );
       
   685 				if ( is_multisite() )
       
   686 					$tables = array_merge( $tables, $this->ms_global_tables );
       
   687 				break;
       
   688 			case 'blog' :
       
   689 				$tables = $this->tables;
       
   690 				break;
       
   691 			case 'global' :
       
   692 				$tables = $this->global_tables;
       
   693 				if ( is_multisite() )
       
   694 					$tables = array_merge( $tables, $this->ms_global_tables );
       
   695 				break;
       
   696 			case 'ms_global' :
       
   697 				$tables = $this->ms_global_tables;
       
   698 				break;
       
   699 			case 'old' :
       
   700 				$tables = $this->old_tables;
       
   701 				break;
       
   702 			default :
       
   703 				return array();
       
   704 				break;
       
   705 		}
       
   706 
       
   707 		if ( $prefix ) {
       
   708 			if ( ! $blog_id )
       
   709 				$blog_id = $this->blogid;
       
   710 			$blog_prefix = $this->get_blog_prefix( $blog_id );
       
   711 			$base_prefix = $this->base_prefix;
       
   712 			$global_tables = array_merge( $this->global_tables, $this->ms_global_tables );
       
   713 			foreach ( $tables as $k => $table ) {
       
   714 				if ( in_array( $table, $global_tables ) )
       
   715 					$tables[ $table ] = $base_prefix . $table;
       
   716 				else
       
   717 					$tables[ $table ] = $blog_prefix . $table;
       
   718 				unset( $tables[ $k ] );
       
   719 			}
       
   720 
       
   721 			if ( isset( $tables['users'] ) && defined( 'CUSTOM_USER_TABLE' ) )
       
   722 				$tables['users'] = CUSTOM_USER_TABLE;
       
   723 
       
   724 			if ( isset( $tables['usermeta'] ) && defined( 'CUSTOM_USER_META_TABLE' ) )
       
   725 				$tables['usermeta'] = CUSTOM_USER_META_TABLE;
       
   726 		}
       
   727 
       
   728 		return $tables;
   443 	}
   729 	}
   444 
   730 
   445 	/**
   731 	/**
   446 	 * Selects a database using the current database connection.
   732 	 * Selects a database using the current database connection.
   447 	 *
   733 	 *
   449 	 * connection. On failure, the execution will bail and display an DB error.
   735 	 * connection. On failure, the execution will bail and display an DB error.
   450 	 *
   736 	 *
   451 	 * @since 0.71
   737 	 * @since 0.71
   452 	 *
   738 	 *
   453 	 * @param string $db MySQL database name
   739 	 * @param string $db MySQL database name
       
   740 	 * @param resource $dbh Optional link identifier.
   454 	 * @return null Always null.
   741 	 * @return null Always null.
   455 	 */
   742 	 */
   456 	function select($db) {
   743 	function select( $db, $dbh = null ) {
   457 		if (!@mysql_select_db($db, $this->dbh)) {
   744 		if ( is_null($dbh) )
       
   745 			$dbh = $this->dbh;
       
   746 
       
   747 		if ( !@mysql_select_db( $db, $dbh ) ) {
   458 			$this->ready = false;
   748 			$this->ready = false;
   459 			$this->bail(sprintf(/*WP_I18N_DB_SELECT_DB*/'
   749 			wp_load_translations_early();
   460 <h1>Impossible de sélectionner la base de données</h1>
   750 			$this->bail( sprintf( __( '<h1>Can&#8217;t select database</h1>
   461 <p>La connexion au serveur de base de données s&rsquo;est bien faite (donc votre identifiant et votre mot de passe sont les bons), mais la base de données <code>%1$s</code> n&rsquo;a pas pu être sélectionnée.</p>
   751 <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>
   462 <ul>
   752 <ul>
   463 <li>Êtes-vous certain(e) qu&rsquo;elle existe&nbsp;?</li>
   753 <li>Are you sure it exists?</li>
   464 <li>L&rsquo;utilisateur <code>%2$s</code> a-t-il les droits pour utiliser la base de donn&eacute; <code>%1$s</code>&nbsp;?</li>
   754 <li>Does the user <code>%2$s</code> have permission to use the <code>%1$s</code> database?</li>
   465 <li>Sur certains systèmes, le nom de votre base de données est préfixée de votre identifiant, donc son nom complet peut être <code>identifiant_nomdelabase</code>. Cela peut-il être la cause du problème&nbps;?</li>
   755 <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>
   466 </ul>
   756 </ul>
   467 <p>Si vous ne savez pas comment régler votre base de données, vous devriez <strong>prendre contact avec votre hébergeur</strong>. Si toutes vos tentatives échouent, peut-être trouverez-vous une réponse sur le <a href=\'http://www.wordpress-fr.net/support/\'>forum d&rsquo;entraide en français</a>.</p>'/*/WP_I18N_DB_SELECT_DB*/, $db, $this->dbuser), 'db_select_fail');
   757 <p>If you don\'t know how to set up 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>' ), htmlspecialchars( $db, ENT_QUOTES ), htmlspecialchars( $this->dbuser, ENT_QUOTES ) ), 'db_select_fail' );
   468 			return;
   758 			return;
   469 		}
   759 		}
   470 	}
   760 	}
   471 
   761 
   472 	function _weak_escape($string) {
   762 	/**
   473 		return addslashes($string);
   763 	 * Weak escape, using addslashes()
   474 	}
   764 	 *
   475 
   765 	 * @see addslashes()
   476 	function _real_escape($string) {
   766 	 * @since 2.8.0
       
   767 	 * @access private
       
   768 	 *
       
   769 	 * @param string $string
       
   770 	 * @return string
       
   771 	 */
       
   772 	function _weak_escape( $string ) {
       
   773 		return addslashes( $string );
       
   774 	}
       
   775 
       
   776 	/**
       
   777 	 * Real escape, using mysql_real_escape_string() or addslashes()
       
   778 	 *
       
   779 	 * @see mysql_real_escape_string()
       
   780 	 * @see addslashes()
       
   781 	 * @since 2.8.0
       
   782 	 * @access private
       
   783 	 *
       
   784 	 * @param  string $string to escape
       
   785 	 * @return string escaped
       
   786 	 */
       
   787 	function _real_escape( $string ) {
   477 		if ( $this->dbh && $this->real_escape )
   788 		if ( $this->dbh && $this->real_escape )
   478 			return mysql_real_escape_string( $string, $this->dbh );
   789 			return mysql_real_escape_string( $string, $this->dbh );
   479 		else
   790 		else
   480 			return addslashes( $string );
   791 			return addslashes( $string );
   481 	}
   792 	}
   482 
   793 
   483 	function _escape($data) {
   794 	/**
   484 		if ( is_array($data) ) {
   795 	 * Escape data. Works on arrays.
       
   796 	 *
       
   797 	 * @uses wpdb::_escape()
       
   798 	 * @uses wpdb::_real_escape()
       
   799 	 * @since  2.8.0
       
   800 	 * @access private
       
   801 	 *
       
   802 	 * @param  string|array $data
       
   803 	 * @return string|array escaped
       
   804 	 */
       
   805 	function _escape( $data ) {
       
   806 		if ( is_array( $data ) ) {
   485 			foreach ( (array) $data as $k => $v ) {
   807 			foreach ( (array) $data as $k => $v ) {
   486 				if ( is_array($v) )
   808 				if ( is_array($v) )
   487 					$data[$k] = $this->_escape( $v );
   809 					$data[$k] = $this->_escape( $v );
   488 				else
   810 				else
   489 					$data[$k] = $this->_real_escape( $v );
   811 					$data[$k] = $this->_real_escape( $v );
   494 
   816 
   495 		return $data;
   817 		return $data;
   496 	}
   818 	}
   497 
   819 
   498 	/**
   820 	/**
   499 	 * Escapes content for insertion into the database using addslashes(), for security
   821 	 * Escapes content for insertion into the database using addslashes(), for security.
       
   822 	 *
       
   823 	 * Works on arrays.
   500 	 *
   824 	 *
   501 	 * @since 0.71
   825 	 * @since 0.71
   502 	 *
   826 	 * @param string|array $data to escape
   503 	 * @param string|array $data
   827 	 * @return string|array escaped as query safe string
   504 	 * @return string query safe string
   828 	 */
   505 	 */
   829 	function escape( $data ) {
   506 	function escape($data) {
   830 		if ( is_array( $data ) ) {
   507 		if ( is_array($data) ) {
       
   508 			foreach ( (array) $data as $k => $v ) {
   831 			foreach ( (array) $data as $k => $v ) {
   509 				if ( is_array($v) )
   832 				if ( is_array( $v ) )
   510 					$data[$k] = $this->escape( $v );
   833 					$data[$k] = $this->escape( $v );
   511 				else
   834 				else
   512 					$data[$k] = $this->_weak_escape( $v );
   835 					$data[$k] = $this->_weak_escape( $v );
   513 			}
   836 			}
   514 		} else {
   837 		} else {
   519 	}
   842 	}
   520 
   843 
   521 	/**
   844 	/**
   522 	 * Escapes content by reference for insertion into the database, for security
   845 	 * Escapes content by reference for insertion into the database, for security
   523 	 *
   846 	 *
       
   847 	 * @uses wpdb::_real_escape()
   524 	 * @since 2.3.0
   848 	 * @since 2.3.0
   525 	 *
   849 	 * @param string $string to escape
   526 	 * @param string $s
   850 	 * @return void
   527 	 */
   851 	 */
   528 	function escape_by_ref(&$string) {
   852 	function escape_by_ref( &$string ) {
   529 		$string = $this->_real_escape( $string );
   853 		$string = $this->_real_escape( $string );
   530 	}
   854 	}
   531 
   855 
   532 	/**
   856 	/**
   533 	 * Prepares a SQL query for safe execution.  Uses sprintf()-like syntax.
   857 	 * Prepares a SQL query for safe execution. Uses sprintf()-like syntax.
   534 	 *
   858 	 *
   535 	 * This function only supports a small subset of the sprintf syntax; it only supports %d (decimal number), %s (string).
   859 	 * The following directives can be used in the query format string:
       
   860 	 *   %d (integer)
       
   861 	 *   %f (float)
       
   862 	 *   %s (string)
       
   863 	 *   %% (literal percentage sign - no argument needed)
       
   864 	 *
       
   865 	 * All of %d, %f, and %s are to be left unquoted in the query string and they need an argument passed for them.
       
   866 	 * Literals (%) as parts of the query must be properly written as %%.
       
   867 	 *
       
   868 	 * This function only supports a small subset of the sprintf syntax; it only supports %d (integer), %f (float), and %s (string).
   536 	 * Does not support sign, padding, alignment, width or precision specifiers.
   869 	 * Does not support sign, padding, alignment, width or precision specifiers.
   537 	 * Does not support argument numbering/swapping.
   870 	 * Does not support argument numbering/swapping.
   538 	 *
   871 	 *
   539 	 * May be called like {@link http://php.net/sprintf sprintf()} or like {@link http://php.net/vsprintf vsprintf()}.
   872 	 * May be called like {@link http://php.net/sprintf sprintf()} or like {@link http://php.net/vsprintf vsprintf()}.
   540 	 *
   873 	 *
   541 	 * Both %d and %s should be left unquoted in the query string.
   874 	 * Both %d and %s should be left unquoted in the query string.
   542 	 *
   875 	 *
   543 	 * <code>
   876 	 * <code>
   544 	 * wpdb::prepare( "SELECT * FROM `table` WHERE `column` = %s AND `field` = %d", "foo", 1337 )
   877 	 * wpdb::prepare( "SELECT * FROM `table` WHERE `column` = %s AND `field` = %d", 'foo', 1337 )
       
   878 	 * wpdb::prepare( "SELECT DATE_FORMAT(`field`, '%%c') FROM `table` WHERE `column` = %s", 'foo' );
   545 	 * </code>
   879 	 * </code>
   546 	 *
   880 	 *
   547 	 * @link http://php.net/sprintf Description of syntax.
   881 	 * @link http://php.net/sprintf Description of syntax.
   548 	 * @since 2.3.0
   882 	 * @since 2.3.0
   549 	 *
   883 	 *
   550 	 * @param string $query Query statement with sprintf()-like placeholders
   884 	 * @param string $query Query statement with sprintf()-like placeholders
   551 	 * @param array|mixed $args The array of variables to substitute into the query's placeholders if being called like {@link http://php.net/vsprintf vsprintf()}, or the first variable to substitute into the query's placeholders if being called like {@link http://php.net/sprintf sprintf()}.
   885 	 * @param array|mixed $args The array of variables to substitute into the query's placeholders if being called like
   552 	 * @param mixed $args,... further variables to substitute into the query's placeholders if being called like {@link http://php.net/sprintf sprintf()}.
   886 	 * 	{@link http://php.net/vsprintf vsprintf()}, or the first variable to substitute into the query's placeholders if
   553 	 * @return null|string Sanitized query string
   887 	 * 	being called like {@link http://php.net/sprintf sprintf()}.
   554 	 */
   888 	 * @param mixed $args,... further variables to substitute into the query's placeholders if being called like
   555 	function prepare($query = null) { // ( $query, *$args )
   889 	 * 	{@link http://php.net/sprintf sprintf()}.
       
   890 	 * @return null|false|string Sanitized query string, null if there is no query, false if there is an error and string
       
   891 	 * 	if there was something to prepare
       
   892 	 */
       
   893 	function prepare( $query = null ) { // ( $query, *$args )
   556 		if ( is_null( $query ) )
   894 		if ( is_null( $query ) )
   557 			return;
   895 			return;
       
   896 
   558 		$args = func_get_args();
   897 		$args = func_get_args();
   559 		array_shift($args);
   898 		array_shift( $args );
   560 		// If args were passed as an array (as in vsprintf), move them up
   899 		// If args were passed as an array (as in vsprintf), move them up
   561 		if ( isset($args[0]) && is_array($args[0]) )
   900 		if ( isset( $args[0] ) && is_array($args[0]) )
   562 			$args = $args[0];
   901 			$args = $args[0];
   563 		$query = str_replace("'%s'", '%s', $query); // in case someone mistakenly already singlequoted it
   902 		$query = str_replace( "'%s'", '%s', $query ); // in case someone mistakenly already singlequoted it
   564 		$query = str_replace('"%s"', '%s', $query); // doublequote unquoting
   903 		$query = str_replace( '"%s"', '%s', $query ); // doublequote unquoting
   565 		$query = str_replace('%s', "'%s'", $query); // quote the strings
   904 		$query = preg_replace( '|(?<!%)%s|', "'%s'", $query ); // quote the strings, avoiding escaped strings like %%s
   566 		array_walk($args, array(&$this, 'escape_by_ref'));
   905 		array_walk( $args, array( &$this, 'escape_by_ref' ) );
   567 		return @vsprintf($query, $args);
   906 		return @vsprintf( $query, $args );
   568 	}
   907 	}
   569 
   908 
   570 	/**
   909 	/**
   571 	 * Print SQL/DB error.
   910 	 * Print SQL/DB error.
   572 	 *
   911 	 *
   574 	 * @global array $EZSQL_ERROR Stores error information of query and error string
   913 	 * @global array $EZSQL_ERROR Stores error information of query and error string
   575 	 *
   914 	 *
   576 	 * @param string $str The error to display
   915 	 * @param string $str The error to display
   577 	 * @return bool False if the showing of errors is disabled.
   916 	 * @return bool False if the showing of errors is disabled.
   578 	 */
   917 	 */
   579 	function print_error($str = '') {
   918 	function print_error( $str = '' ) {
   580 		global $EZSQL_ERROR;
   919 		global $EZSQL_ERROR;
   581 
   920 
   582 		if (!$str) $str = mysql_error($this->dbh);
   921 		if ( !$str )
   583 		$EZSQL_ERROR[] = array ('query' => $this->last_query, 'error_str' => $str);
   922 			$str = mysql_error( $this->dbh );
       
   923 		$EZSQL_ERROR[] = array( 'query' => $this->last_query, 'error_str' => $str );
   584 
   924 
   585 		if ( $this->suppress_errors )
   925 		if ( $this->suppress_errors )
   586 			return false;
   926 			return false;
   587 
   927 
       
   928 		wp_load_translations_early();
       
   929 
   588 		if ( $caller = $this->get_caller() )
   930 		if ( $caller = $this->get_caller() )
   589 			$error_str = sprintf(/*WP_I18N_DB_QUERY_ERROR_FULL*/'Erreur de la base de données WordPress %1$s pour la requête %2$s faite par %3$s'/*/WP_I18N_DB_QUERY_ERROR_FULL*/, $str, $this->last_query, $caller);
   931 			$error_str = sprintf( __( 'WordPress database error %1$s for query %2$s made by %3$s' ), $str, $this->last_query, $caller );
   590 		else
   932 		else
   591 			$error_str = sprintf(/*WP_I18N_DB_QUERY_ERROR*/'Erreur de la base de données WordPress %1$s pour la requête %2$s'/*/WP_I18N_DB_QUERY_ERROR*/, $str, $this->last_query);
   933 			$error_str = sprintf( __( 'WordPress database error %1$s for query %2$s' ), $str, $this->last_query );
   592 
   934 
   593 		$log_error = true;
   935 		if ( function_exists( 'error_log' )
   594 		if ( ! function_exists('error_log') )
   936 			&& ( $log_file = @ini_get( 'error_log' ) )
   595 			$log_error = false;
   937 			&& ( 'syslog' == $log_file || @is_writable( $log_file ) )
   596 
   938 			)
   597 		$log_file = @ini_get('error_log');
   939 			@error_log( $error_str );
   598 		if ( !empty($log_file) && ('syslog' != $log_file) && !@is_writable($log_file) )
   940 
   599 			$log_error = false;
   941 		// Are we showing errors?
   600 
   942 		if ( ! $this->show_errors )
   601 		if ( $log_error )
       
   602 			@error_log($error_str, 0);
       
   603 
       
   604 		// Is error output turned on or not..
       
   605 		if ( !$this->show_errors )
       
   606 			return false;
   943 			return false;
   607 
   944 
   608 		$str = htmlspecialchars($str, ENT_QUOTES);
       
   609 		$query = htmlspecialchars($this->last_query, ENT_QUOTES);
       
   610 
       
   611 		// If there is an error then take note of it
   945 		// If there is an error then take note of it
   612 		print "<div id='error'>
   946 		if ( is_multisite() ) {
   613 		<p class='wpdberror'><strong>WordPress database error:</strong> [$str]<br />
   947 			$msg = "WordPress database error: [$str]\n{$this->last_query}\n";
   614 		<code>$query</code></p>
   948 			if ( defined( 'ERRORLOGFILE' ) )
   615 		</div>";
   949 				error_log( $msg, 3, ERRORLOGFILE );
       
   950 			if ( defined( 'DIEONDBERROR' ) )
       
   951 				wp_die( $msg );
       
   952 		} else {
       
   953 			$str   = htmlspecialchars( $str, ENT_QUOTES );
       
   954 			$query = htmlspecialchars( $this->last_query, ENT_QUOTES );
       
   955 
       
   956 			print "<div id='error'>
       
   957 			<p class='wpdberror'><strong>WordPress database error:</strong> [$str]<br />
       
   958 			<code>$query</code></p>
       
   959 			</div>";
       
   960 		}
   616 	}
   961 	}
   617 
   962 
   618 	/**
   963 	/**
   619 	 * Enables showing of database errors.
   964 	 * Enables showing of database errors.
   620 	 *
   965 	 *
   622 	 * wpdb::hide_errors() should be used instead for hiding of errors. However,
   967 	 * wpdb::hide_errors() should be used instead for hiding of errors. However,
   623 	 * this function can be used to enable and disable showing of database
   968 	 * this function can be used to enable and disable showing of database
   624 	 * errors.
   969 	 * errors.
   625 	 *
   970 	 *
   626 	 * @since 0.71
   971 	 * @since 0.71
       
   972 	 * @see wpdb::hide_errors()
   627 	 *
   973 	 *
   628 	 * @param bool $show Whether to show or hide errors
   974 	 * @param bool $show Whether to show or hide errors
   629 	 * @return bool Old value for showing errors.
   975 	 * @return bool Old value for showing errors.
   630 	 */
   976 	 */
   631 	function show_errors( $show = true ) {
   977 	function show_errors( $show = true ) {
   635 	}
   981 	}
   636 
   982 
   637 	/**
   983 	/**
   638 	 * Disables showing of database errors.
   984 	 * Disables showing of database errors.
   639 	 *
   985 	 *
       
   986 	 * By default database errors are not shown.
       
   987 	 *
   640 	 * @since 0.71
   988 	 * @since 0.71
   641 	 *
   989 	 * @see wpdb::show_errors()
   642 	 * @return bool Whether showing of errors was active or not
   990 	 *
       
   991 	 * @return bool Whether showing of errors was active
   643 	 */
   992 	 */
   644 	function hide_errors() {
   993 	function hide_errors() {
   645 		$show = $this->show_errors;
   994 		$show = $this->show_errors;
   646 		$this->show_errors = false;
   995 		$this->show_errors = false;
   647 		return $show;
   996 		return $show;
   648 	}
   997 	}
   649 
   998 
   650 	/**
   999 	/**
   651 	 * Whether to suppress database errors.
  1000 	 * Whether to suppress database errors.
   652 	 *
  1001 	 *
   653 	 * @param unknown_type $suppress
  1002 	 * By default database errors are suppressed, with a simple
   654 	 * @return unknown
  1003 	 * call to this function they can be enabled.
       
  1004 	 *
       
  1005 	 * @since 2.5.0
       
  1006 	 * @see wpdb::hide_errors()
       
  1007 	 * @param bool $suppress Optional. New value. Defaults to true.
       
  1008 	 * @return bool Old value
   655 	 */
  1009 	 */
   656 	function suppress_errors( $suppress = true ) {
  1010 	function suppress_errors( $suppress = true ) {
   657 		$errors = $this->suppress_errors;
  1011 		$errors = $this->suppress_errors;
   658 		$this->suppress_errors = $suppress;
  1012 		$this->suppress_errors = (bool) $suppress;
   659 		return $errors;
  1013 		return $errors;
   660 	}
  1014 	}
   661 
  1015 
   662 	/**
  1016 	/**
   663 	 * Kill cached query results.
  1017 	 * Kill cached query results.
   664 	 *
  1018 	 *
   665 	 * @since 0.71
  1019 	 * @since 0.71
       
  1020 	 * @return void
   666 	 */
  1021 	 */
   667 	function flush() {
  1022 	function flush() {
   668 		$this->last_result = array();
  1023 		$this->last_result = array();
   669 		$this->col_info = null;
  1024 		$this->col_info    = null;
   670 		$this->last_query = null;
  1025 		$this->last_query  = null;
       
  1026 	}
       
  1027 
       
  1028 	/**
       
  1029 	 * Connect to and select database
       
  1030 	 *
       
  1031 	 * @since 3.0.0
       
  1032 	 */
       
  1033 	function db_connect() {
       
  1034 
       
  1035 		$this->is_mysql = true;
       
  1036 
       
  1037 		if ( WP_DEBUG ) {
       
  1038 			$this->dbh = mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, true );
       
  1039 		} else {
       
  1040 			$this->dbh = @mysql_connect( $this->dbhost, $this->dbuser, $this->dbpassword, true );
       
  1041 		}
       
  1042 
       
  1043 		if ( !$this->dbh ) {
       
  1044 			wp_load_translations_early();
       
  1045 			$this->bail( sprintf( __( "
       
  1046 <h1>Error establishing a database connection</h1>
       
  1047 <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>
       
  1048 <ul>
       
  1049 	<li>Are you sure you have the correct username and password?</li>
       
  1050 	<li>Are you sure that you have typed the correct hostname?</li>
       
  1051 	<li>Are you sure that the database server is running?</li>
       
  1052 </ul>
       
  1053 <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>
       
  1054 " ), htmlspecialchars( $this->dbhost, ENT_QUOTES ) ), 'db_connect_fail' );
       
  1055 
       
  1056 			return;
       
  1057 		}
       
  1058 
       
  1059 		$this->set_charset( $this->dbh );
       
  1060 
       
  1061 		$this->ready = true;
       
  1062 
       
  1063 		$this->select( $this->dbname, $this->dbh );
   671 	}
  1064 	}
   672 
  1065 
   673 	/**
  1066 	/**
   674 	 * Perform a MySQL database query, using current database connection.
  1067 	 * Perform a MySQL database query, using current database connection.
   675 	 *
  1068 	 *
   676 	 * More information can be found on the codex page.
  1069 	 * More information can be found on the codex page.
   677 	 *
  1070 	 *
   678 	 * @since 0.71
  1071 	 * @since 0.71
   679 	 *
  1072 	 *
   680 	 * @param string $query
  1073 	 * @param string $query Database query
   681 	 * @return int|false Number of rows affected/selected or false on error
  1074 	 * @return int|false Number of rows affected/selected or false on error
   682 	 */
  1075 	 */
   683 	function query($query) {
  1076 	function query( $query ) {
   684 		if ( ! $this->ready )
  1077 		if ( ! $this->ready )
   685 			return false;
  1078 			return false;
   686 
  1079 
   687 		// filter the query, if filters are available
  1080 		// some queries are made before the plugins have been loaded, and thus cannot be filtered with this method
   688 		// NOTE: some queries are made before the plugins have been loaded, and thus cannot be filtered with this method
  1081 		$query = apply_filters( 'query', $query );
   689 		if ( function_exists('apply_filters') )
  1082 
   690 			$query = apply_filters('query', $query);
       
   691 
       
   692 		// initialise return
       
   693 		$return_val = 0;
  1083 		$return_val = 0;
   694 		$this->flush();
  1084 		$this->flush();
   695 
  1085 
   696 		// Log how the function was called
  1086 		// Log how the function was called
   697 		$this->func_call = "\$db->query(\"$query\")";
  1087 		$this->func_call = "\$db->query(\"$query\")";
   698 
  1088 
   699 		// Keep track of the last query for debug..
  1089 		// Keep track of the last query for debug..
   700 		$this->last_query = $query;
  1090 		$this->last_query = $query;
   701 
  1091 
   702 		// Perform the query via std mysql_query function..
  1092 		if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES )
   703 		if ( defined('SAVEQUERIES') && SAVEQUERIES )
       
   704 			$this->timer_start();
  1093 			$this->timer_start();
   705 
  1094 
   706 		$this->result = @mysql_query($query, $this->dbh);
  1095 		$this->result = @mysql_query( $query, $this->dbh );
   707 		++$this->num_queries;
  1096 		$this->num_queries++;
   708 
  1097 
   709 		if ( defined('SAVEQUERIES') && SAVEQUERIES )
  1098 		if ( defined( 'SAVEQUERIES' ) && SAVEQUERIES )
   710 			$this->queries[] = array( $query, $this->timer_stop(), $this->get_caller() );
  1099 			$this->queries[] = array( $query, $this->timer_stop(), $this->get_caller() );
   711 
  1100 
   712 		// If there is an error then take note of it..
  1101 		// If there is an error then take note of it..
   713 		if ( $this->last_error = mysql_error($this->dbh) ) {
  1102 		if ( $this->last_error = mysql_error( $this->dbh ) ) {
   714 			$this->print_error();
  1103 			$this->print_error();
   715 			return false;
  1104 			return false;
   716 		}
  1105 		}
   717 
  1106 
   718 		if ( preg_match("/^\\s*(insert|delete|update|replace|alter) /i",$query) ) {
  1107 		if ( preg_match( '/^\s*(create|alter|truncate|drop) /i', $query ) ) {
   719 			$this->rows_affected = mysql_affected_rows($this->dbh);
  1108 			$return_val = $this->result;
       
  1109 		} elseif ( preg_match( '/^\s*(insert|delete|update|replace) /i', $query ) ) {
       
  1110 			$this->rows_affected = mysql_affected_rows( $this->dbh );
   720 			// Take note of the insert_id
  1111 			// Take note of the insert_id
   721 			if ( preg_match("/^\\s*(insert|replace) /i",$query) ) {
  1112 			if ( preg_match( '/^\s*(insert|replace) /i', $query ) ) {
   722 				$this->insert_id = mysql_insert_id($this->dbh);
  1113 				$this->insert_id = mysql_insert_id($this->dbh);
   723 			}
  1114 			}
   724 			// Return number of rows affected
  1115 			// Return number of rows affected
   725 			$return_val = $this->rows_affected;
  1116 			$return_val = $this->rows_affected;
   726 		} else {
  1117 		} else {
   727 			$i = 0;
  1118 			$i = 0;
   728 			while ($i < @mysql_num_fields($this->result)) {
  1119 			while ( $i < @mysql_num_fields( $this->result ) ) {
   729 				$this->col_info[$i] = @mysql_fetch_field($this->result);
  1120 				$this->col_info[$i] = @mysql_fetch_field( $this->result );
   730 				$i++;
  1121 				$i++;
   731 			}
  1122 			}
   732 			$num_rows = 0;
  1123 			$num_rows = 0;
   733 			while ( $row = @mysql_fetch_object($this->result) ) {
  1124 			while ( $row = @mysql_fetch_object( $this->result ) ) {
   734 				$this->last_result[$num_rows] = $row;
  1125 				$this->last_result[$num_rows] = $row;
   735 				$num_rows++;
  1126 				$num_rows++;
   736 			}
  1127 			}
   737 
  1128 
   738 			@mysql_free_result($this->result);
  1129 			@mysql_free_result( $this->result );
   739 
  1130 
   740 			// Log number of rows the query returned
  1131 			// Log number of rows the query returned
       
  1132 			// and return number of rows selected
   741 			$this->num_rows = $num_rows;
  1133 			$this->num_rows = $num_rows;
   742 
  1134 			$return_val     = $num_rows;
   743 			// Return number of rows selected
       
   744 			$return_val = $this->num_rows;
       
   745 		}
  1135 		}
   746 
  1136 
   747 		return $return_val;
  1137 		return $return_val;
   748 	}
  1138 	}
   749 
  1139 
   750 	/**
  1140 	/**
   751 	 * Insert a row into a table.
  1141 	 * Insert a row into a table.
   752 	 *
  1142 	 *
   753 	 * <code>
  1143 	 * <code>
       
  1144 	 * wpdb::insert( 'table', array( 'column' => 'foo', 'field' => 'bar' ) )
   754 	 * wpdb::insert( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( '%s', '%d' ) )
  1145 	 * wpdb::insert( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( '%s', '%d' ) )
   755 	 * </code>
  1146 	 * </code>
   756 	 *
  1147 	 *
   757 	 * @since 2.5.0
  1148 	 * @since 2.5.0
   758 	 * @see wpdb::prepare()
  1149 	 * @see wpdb::prepare()
       
  1150 	 * @see wpdb::$field_types
       
  1151 	 * @see wp_set_wpdb_vars()
   759 	 *
  1152 	 *
   760 	 * @param string $table table name
  1153 	 * @param string $table table name
   761 	 * @param array $data Data to insert (in column => value pairs).  Both $data columns and $data values should be "raw" (neither should be SQL escaped).
  1154 	 * @param array $data Data to insert (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped).
   762 	 * @param array|string $format (optional) An array of formats to be mapped to each of the value in $data.  If string, that format will be used for all of the values in $data.  A format is one of '%d', '%s' (decimal number, string).  If omitted, all values in $data will be treated as strings.
  1155 	 * @param array|string $format Optional. An array of formats to be mapped to each of the value in $data. If string, that format will be used for all of the values in $data.
       
  1156 	 * 	A format is one of '%d', '%f', '%s' (integer, float, string). If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types.
   763 	 * @return int|false The number of rows inserted, or false on error.
  1157 	 * @return int|false The number of rows inserted, or false on error.
   764 	 */
  1158 	 */
   765 	function insert($table, $data, $format = null) {
  1159 	function insert( $table, $data, $format = null ) {
       
  1160 		return $this->_insert_replace_helper( $table, $data, $format, 'INSERT' );
       
  1161 	}
       
  1162 
       
  1163 	/**
       
  1164 	 * Replace a row into a table.
       
  1165 	 *
       
  1166 	 * <code>
       
  1167 	 * wpdb::replace( 'table', array( 'column' => 'foo', 'field' => 'bar' ) )
       
  1168 	 * wpdb::replace( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( '%s', '%d' ) )
       
  1169 	 * </code>
       
  1170 	 *
       
  1171 	 * @since 3.0.0
       
  1172 	 * @see wpdb::prepare()
       
  1173 	 * @see wpdb::$field_types
       
  1174 	 * @see wp_set_wpdb_vars()
       
  1175 	 *
       
  1176 	 * @param string $table table name
       
  1177 	 * @param array $data Data to insert (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped).
       
  1178 	 * @param array|string $format Optional. An array of formats to be mapped to each of the value in $data. If string, that format will be used for all of the values in $data.
       
  1179 	 * 	A format is one of '%d', '%f', '%s' (integer, float, string). If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types.
       
  1180 	 * @return int|false The number of rows affected, or false on error.
       
  1181 	 */
       
  1182 	function replace( $table, $data, $format = null ) {
       
  1183 		return $this->_insert_replace_helper( $table, $data, $format, 'REPLACE' );
       
  1184 	}
       
  1185 
       
  1186 	/**
       
  1187 	 * Helper function for insert and replace.
       
  1188 	 *
       
  1189 	 * Runs an insert or replace query based on $type argument.
       
  1190 	 *
       
  1191 	 * @access private
       
  1192 	 * @since 3.0.0
       
  1193 	 * @see wpdb::prepare()
       
  1194 	 * @see wpdb::$field_types
       
  1195 	 * @see wp_set_wpdb_vars()
       
  1196 	 *
       
  1197 	 * @param string $table table name
       
  1198 	 * @param array $data Data to insert (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped).
       
  1199 	 * @param array|string $format Optional. An array of formats to be mapped to each of the value in $data. If string, that format will be used for all of the values in $data.
       
  1200 	 * 	A format is one of '%d', '%f', '%s' (integer, float, string). If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types.
       
  1201 	 * @param string $type Optional. What type of operation is this? INSERT or REPLACE. Defaults to INSERT.
       
  1202 	 * @return int|false The number of rows affected, or false on error.
       
  1203 	 */
       
  1204 	function _insert_replace_helper( $table, $data, $format = null, $type = 'INSERT' ) {
       
  1205 		if ( ! in_array( strtoupper( $type ), array( 'REPLACE', 'INSERT' ) ) )
       
  1206 			return false;
   766 		$formats = $format = (array) $format;
  1207 		$formats = $format = (array) $format;
   767 		$fields = array_keys($data);
  1208 		$fields = array_keys( $data );
   768 		$formatted_fields = array();
  1209 		$formatted_fields = array();
   769 		foreach ( $fields as $field ) {
  1210 		foreach ( $fields as $field ) {
   770 			if ( !empty($format) )
  1211 			if ( !empty( $format ) )
   771 				$form = ( $form = array_shift($formats) ) ? $form : $format[0];
  1212 				$form = ( $form = array_shift( $formats ) ) ? $form : $format[0];
   772 			elseif ( isset($this->field_types[$field]) )
  1213 			elseif ( isset( $this->field_types[$field] ) )
   773 				$form = $this->field_types[$field];
  1214 				$form = $this->field_types[$field];
   774 			else
  1215 			else
   775 				$form = '%s';
  1216 				$form = '%s';
   776 			$formatted_fields[] = $form;
  1217 			$formatted_fields[] = $form;
   777 		}
  1218 		}
   778 		$sql = "INSERT INTO `$table` (`" . implode( '`,`', $fields ) . "`) VALUES ('" . implode( "','", $formatted_fields ) . "')";
  1219 		$sql = "{$type} INTO `$table` (`" . implode( '`,`', $fields ) . "`) VALUES (" . implode( ",", $formatted_fields ) . ")";
   779 		return $this->query( $this->prepare( $sql, $data) );
  1220 		return $this->query( $this->prepare( $sql, $data ) );
   780 	}
  1221 	}
   781 
       
   782 
  1222 
   783 	/**
  1223 	/**
   784 	 * Update a row in the table
  1224 	 * Update a row in the table
   785 	 *
  1225 	 *
   786 	 * <code>
  1226 	 * <code>
       
  1227 	 * wpdb::update( 'table', array( 'column' => 'foo', 'field' => 'bar' ), array( 'ID' => 1 ) )
   787 	 * wpdb::update( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( 'ID' => 1 ), array( '%s', '%d' ), array( '%d' ) )
  1228 	 * wpdb::update( 'table', array( 'column' => 'foo', 'field' => 1337 ), array( 'ID' => 1 ), array( '%s', '%d' ), array( '%d' ) )
   788 	 * </code>
  1229 	 * </code>
   789 	 *
  1230 	 *
   790 	 * @since 2.5.0
  1231 	 * @since 2.5.0
   791 	 * @see wpdb::prepare()
  1232 	 * @see wpdb::prepare()
       
  1233 	 * @see wpdb::$field_types
       
  1234 	 * @see wp_set_wpdb_vars()
   792 	 *
  1235 	 *
   793 	 * @param string $table table name
  1236 	 * @param string $table table name
   794 	 * @param array $data Data to update (in column => value pairs).  Both $data columns and $data values should be "raw" (neither should be SQL escaped).
  1237 	 * @param array $data Data to update (in column => value pairs). Both $data columns and $data values should be "raw" (neither should be SQL escaped).
   795 	 * @param array $where A named array of WHERE clauses (in column => value pairs).  Multiple clauses will be joined with ANDs.  Both $where columns and $where values should be "raw".
  1238 	 * @param array $where A named array of WHERE clauses (in column => value pairs). Multiple clauses will be joined with ANDs. Both $where columns and $where values should be "raw".
   796 	 * @param array|string $format (optional) An array of formats to be mapped to each of the values in $data.  If string, that format will be used for all of the values in $data.  A format is one of '%d', '%s' (decimal number, string).  If omitted, all values in $data will be treated as strings.
  1239 	 * @param array|string $format Optional. An array of formats to be mapped to each of the values in $data. If string, that format will be used for all of the values in $data.
   797 	 * @param array|string $format_where (optional) An array of formats to be mapped to each of the values in $where.  If string, that format will be used for all of  the items in $where.  A format is one of '%d', '%s' (decimal number, string).  If omitted, all values in $where will be treated as strings.
  1240 	 * 	A format is one of '%d', '%f', '%s' (integer, float, string). If omitted, all values in $data will be treated as strings unless otherwise specified in wpdb::$field_types.
       
  1241 	 * @param array|string $where_format Optional. An array of formats to be mapped to each of the values in $where. If string, that format will be used for all of the items in $where. A format is one of '%d', '%f', '%s' (integer, float, string). If omitted, all values in $where will be treated as strings.
   798 	 * @return int|false The number of rows updated, or false on error.
  1242 	 * @return int|false The number of rows updated, or false on error.
   799 	 */
  1243 	 */
   800 	function update($table, $data, $where, $format = null, $where_format = null) {
  1244 	function update( $table, $data, $where, $format = null, $where_format = null ) {
   801 		if ( !is_array( $where ) )
  1245 		if ( ! is_array( $data ) || ! is_array( $where ) )
   802 			return false;
  1246 			return false;
   803 
  1247 
   804 		$formats = $format = (array) $format;
  1248 		$formats = $format = (array) $format;
   805 		$bits = $wheres = array();
  1249 		$bits = $wheres = array();
   806 		foreach ( (array) array_keys($data) as $field ) {
  1250 		foreach ( (array) array_keys( $data ) as $field ) {
   807 			if ( !empty($format) )
  1251 			if ( !empty( $format ) )
   808 				$form = ( $form = array_shift($formats) ) ? $form : $format[0];
  1252 				$form = ( $form = array_shift( $formats ) ) ? $form : $format[0];
   809 			elseif ( isset($this->field_types[$field]) )
  1253 			elseif ( isset($this->field_types[$field]) )
   810 				$form = $this->field_types[$field];
  1254 				$form = $this->field_types[$field];
   811 			else
  1255 			else
   812 				$form = '%s';
  1256 				$form = '%s';
   813 			$bits[] = "`$field` = {$form}";
  1257 			$bits[] = "`$field` = {$form}";
   814 		}
  1258 		}
   815 
  1259 
   816 		$where_formats = $where_format = (array) $where_format;
  1260 		$where_formats = $where_format = (array) $where_format;
   817 		foreach ( (array) array_keys($where) as $field ) {
  1261 		foreach ( (array) array_keys( $where ) as $field ) {
   818 			if ( !empty($where_format) )
  1262 			if ( !empty( $where_format ) )
   819 				$form = ( $form = array_shift($where_formats) ) ? $form : $where_format[0];
  1263 				$form = ( $form = array_shift( $where_formats ) ) ? $form : $where_format[0];
   820 			elseif ( isset($this->field_types[$field]) )
  1264 			elseif ( isset( $this->field_types[$field] ) )
   821 				$form = $this->field_types[$field];
  1265 				$form = $this->field_types[$field];
   822 			else
  1266 			else
   823 				$form = '%s';
  1267 				$form = '%s';
   824 			$wheres[] = "`$field` = {$form}";
  1268 			$wheres[] = "`$field` = {$form}";
   825 		}
  1269 		}
   826 
  1270 
   827 		$sql = "UPDATE `$table` SET " . implode( ', ', $bits ) . ' WHERE ' . implode( ' AND ', $wheres );
  1271 		$sql = "UPDATE `$table` SET " . implode( ', ', $bits ) . ' WHERE ' . implode( ' AND ', $wheres );
   828 		return $this->query( $this->prepare( $sql, array_merge(array_values($data), array_values($where))) );
  1272 		return $this->query( $this->prepare( $sql, array_merge( array_values( $data ), array_values( $where ) ) ) );
   829 	}
  1273 	}
       
  1274 
       
  1275 	/**
       
  1276 	 * Delete a row in the table
       
  1277 	 *
       
  1278 	 * <code>
       
  1279 	 * wpdb::delete( 'table', array( 'ID' => 1 ) )
       
  1280 	 * wpdb::delete( 'table', array( 'ID' => 1 ), array( '%d' ) )
       
  1281 	 * </code>
       
  1282 	 *
       
  1283 	 * @since 3.4.0
       
  1284 	 * @see wpdb::prepare()
       
  1285 	 * @see wpdb::$field_types
       
  1286 	 * @see wp_set_wpdb_vars()
       
  1287 	 *
       
  1288 	 * @param string $table table name
       
  1289 	 * @param array $where A named array of WHERE clauses (in column => value pairs). Multiple clauses will be joined with ANDs. Both $where columns and $where values should be "raw".
       
  1290 	 * @param array|string $where_format Optional. An array of formats to be mapped to each of the values in $where. If string, that format will be used for all of the items in $where. A format is one of '%d', '%f', '%s' (integer, float, string). If omitted, all values in $where will be treated as strings unless otherwise specified in wpdb::$field_types.
       
  1291 	 * @return int|false The number of rows updated, or false on error.
       
  1292 	 */
       
  1293 	function delete( $table, $where, $where_format = null ) {
       
  1294 		if ( ! is_array( $where ) )
       
  1295 			return false;
       
  1296 
       
  1297 		$bits = $wheres = array();
       
  1298 
       
  1299 		$where_formats = $where_format = (array) $where_format;
       
  1300 
       
  1301 		foreach ( array_keys( $where ) as $field ) {
       
  1302 			if ( !empty( $where_format ) ) {
       
  1303 				$form = ( $form = array_shift( $where_formats ) ) ? $form : $where_format[0];
       
  1304 			} elseif ( isset( $this->field_types[ $field ] ) ) {
       
  1305 				$form = $this->field_types[ $field ];
       
  1306 			} else {
       
  1307 				$form = '%s';
       
  1308 			}
       
  1309 
       
  1310 			$wheres[] = "$field = $form";
       
  1311 		}
       
  1312 
       
  1313 		$sql = "DELETE FROM $table WHERE " . implode( ' AND ', $wheres );
       
  1314 		return $this->query( $this->prepare( $sql, $where ) );
       
  1315 	}
       
  1316 
   830 
  1317 
   831 	/**
  1318 	/**
   832 	 * Retrieve one variable from the database.
  1319 	 * Retrieve one variable from the database.
   833 	 *
  1320 	 *
   834 	 * Executes a SQL query and returns the value from the SQL result.
  1321 	 * Executes a SQL query and returns the value from the SQL result.
   835 	 * If the SQL result contains more than one column and/or more than one row, this function returns the value in the column and row specified.
  1322 	 * If the SQL result contains more than one column and/or more than one row, this function returns the value in the column and row specified.
   836 	 * If $query is null, this function returns the value in the specified column and row from the previous SQL result.
  1323 	 * If $query is null, this function returns the value in the specified column and row from the previous SQL result.
   837 	 *
  1324 	 *
   838 	 * @since 0.71
  1325 	 * @since 0.71
   839 	 *
  1326 	 *
   840 	 * @param string|null $query SQL query.  If null, use the result from the previous query.
  1327 	 * @param string|null $query Optional. SQL query. Defaults to null, use the result from the previous query.
   841 	 * @param int $x (optional) Column of value to return.  Indexed from 0.
  1328 	 * @param int $x Optional. Column of value to return. Indexed from 0.
   842 	 * @param int $y (optional) Row of value to return.  Indexed from 0.
  1329 	 * @param int $y Optional. Row of value to return. Indexed from 0.
   843 	 * @return string Database query result
  1330 	 * @return string|null Database query result (as string), or null on failure
   844 	 */
  1331 	 */
   845 	function get_var($query=null, $x = 0, $y = 0) {
  1332 	function get_var( $query = null, $x = 0, $y = 0 ) {
   846 		$this->func_call = "\$db->get_var(\"$query\",$x,$y)";
  1333 		$this->func_call = "\$db->get_var(\"$query\", $x, $y)";
   847 		if ( $query )
  1334 		if ( $query )
   848 			$this->query($query);
  1335 			$this->query( $query );
   849 
  1336 
   850 		// Extract var out of cached results based x,y vals
  1337 		// Extract var out of cached results based x,y vals
   851 		if ( !empty( $this->last_result[$y] ) ) {
  1338 		if ( !empty( $this->last_result[$y] ) ) {
   852 			$values = array_values(get_object_vars($this->last_result[$y]));
  1339 			$values = array_values( get_object_vars( $this->last_result[$y] ) );
   853 		}
  1340 		}
   854 
  1341 
   855 		// If there is a value return it else return null
  1342 		// If there is a value return it else return null
   856 		return (isset($values[$x]) && $values[$x]!=='') ? $values[$x] : null;
  1343 		return ( isset( $values[$x] ) && $values[$x] !== '' ) ? $values[$x] : null;
   857 	}
  1344 	}
   858 
  1345 
   859 	/**
  1346 	/**
   860 	 * Retrieve one row from the database.
  1347 	 * Retrieve one row from the database.
   861 	 *
  1348 	 *
   862 	 * Executes a SQL query and returns the row from the SQL result.
  1349 	 * Executes a SQL query and returns the row from the SQL result.
   863 	 *
  1350 	 *
   864 	 * @since 0.71
  1351 	 * @since 0.71
   865 	 *
  1352 	 *
   866 	 * @param string|null $query SQL query.
  1353 	 * @param string|null $query SQL query.
   867 	 * @param string $output (optional) one of ARRAY_A | ARRAY_N | OBJECT constants.  Return an associative array (column => value, ...), a numerically indexed array (0 => value, ...) or an object ( ->column = value ), respectively.
  1354 	 * @param string $output Optional. one of ARRAY_A | ARRAY_N | OBJECT constants. Return an associative array (column => value, ...),
   868 	 * @param int $y (optional) Row to return.  Indexed from 0.
  1355 	 * 	a numerically indexed array (0 => value, ...) or an object ( ->column = value ), respectively.
   869 	 * @return mixed Database query result in format specifed by $output
  1356 	 * @param int $y Optional. Row to return. Indexed from 0.
   870 	 */
  1357 	 * @return mixed Database query result in format specified by $output or null on failure
   871 	function get_row($query = null, $output = OBJECT, $y = 0) {
  1358 	 */
       
  1359 	function get_row( $query = null, $output = OBJECT, $y = 0 ) {
   872 		$this->func_call = "\$db->get_row(\"$query\",$output,$y)";
  1360 		$this->func_call = "\$db->get_row(\"$query\",$output,$y)";
   873 		if ( $query )
  1361 		if ( $query )
   874 			$this->query($query);
  1362 			$this->query( $query );
   875 		else
  1363 		else
   876 			return null;
  1364 			return null;
   877 
  1365 
   878 		if ( !isset($this->last_result[$y]) )
  1366 		if ( !isset( $this->last_result[$y] ) )
   879 			return null;
  1367 			return null;
   880 
  1368 
   881 		if ( $output == OBJECT ) {
  1369 		if ( $output == OBJECT ) {
   882 			return $this->last_result[$y] ? $this->last_result[$y] : null;
  1370 			return $this->last_result[$y] ? $this->last_result[$y] : null;
   883 		} elseif ( $output == ARRAY_A ) {
  1371 		} elseif ( $output == ARRAY_A ) {
   884 			return $this->last_result[$y] ? get_object_vars($this->last_result[$y]) : null;
  1372 			return $this->last_result[$y] ? get_object_vars( $this->last_result[$y] ) : null;
   885 		} elseif ( $output == ARRAY_N ) {
  1373 		} elseif ( $output == ARRAY_N ) {
   886 			return $this->last_result[$y] ? array_values(get_object_vars($this->last_result[$y])) : null;
  1374 			return $this->last_result[$y] ? array_values( get_object_vars( $this->last_result[$y] ) ) : null;
   887 		} else {
  1375 		} else {
   888 			$this->print_error(/*WP_I18N_DB_GETROW_ERROR*/' $db->get_row(string query, output type, int offset) -- Le type de sortie doit être: OBJECT, ARRAY_A, ARRAY_N'/*/WP_I18N_DB_GETROW_ERROR*/);
  1376 			$this->print_error( " \$db->get_row(string query, output type, int offset) -- Output type must be one of: OBJECT, ARRAY_A, ARRAY_N" );
   889 		}
  1377 		}
   890 	}
  1378 	}
   891 
  1379 
   892 	/**
  1380 	/**
   893 	 * Retrieve one column from the database.
  1381 	 * Retrieve one column from the database.
   896 	 * If the SQL result contains more than one column, this function returns the column specified.
  1384 	 * If the SQL result contains more than one column, this function returns the column specified.
   897 	 * If $query is null, this function returns the specified column from the previous SQL result.
  1385 	 * If $query is null, this function returns the specified column from the previous SQL result.
   898 	 *
  1386 	 *
   899 	 * @since 0.71
  1387 	 * @since 0.71
   900 	 *
  1388 	 *
   901 	 * @param string|null $query SQL query.  If null, use the result from the previous query.
  1389 	 * @param string|null $query Optional. SQL query. Defaults to previous query.
   902 	 * @param int $x Column to return.  Indexed from 0.
  1390 	 * @param int $x Optional. Column to return. Indexed from 0.
   903 	 * @return array Database query result.  Array indexed from 0 by SQL result row number.
  1391 	 * @return array Database query result. Array indexed from 0 by SQL result row number.
   904 	 */
  1392 	 */
   905 	function get_col($query = null , $x = 0) {
  1393 	function get_col( $query = null , $x = 0 ) {
   906 		if ( $query )
  1394 		if ( $query )
   907 			$this->query($query);
  1395 			$this->query( $query );
   908 
  1396 
   909 		$new_array = array();
  1397 		$new_array = array();
   910 		// Extract the column values
  1398 		// Extract the column values
   911 		for ( $i=0; $i < count($this->last_result); $i++ ) {
  1399 		for ( $i = 0, $j = count( $this->last_result ); $i < $j; $i++ ) {
   912 			$new_array[$i] = $this->get_var(null, $x, $i);
  1400 			$new_array[$i] = $this->get_var( null, $x, $i );
   913 		}
  1401 		}
   914 		return $new_array;
  1402 		return $new_array;
   915 	}
  1403 	}
   916 
  1404 
   917 	/**
  1405 	/**
   920 	 * Executes a SQL query and returns the entire SQL result.
  1408 	 * Executes a SQL query and returns the entire SQL result.
   921 	 *
  1409 	 *
   922 	 * @since 0.71
  1410 	 * @since 0.71
   923 	 *
  1411 	 *
   924 	 * @param string $query SQL query.
  1412 	 * @param string $query SQL query.
   925 	 * @param string $output (optional) ane of ARRAY_A | ARRAY_N | OBJECT | OBJECT_K constants.  With one of the first three, return an array of rows indexed from 0 by SQL result row number.  Each row is an associative array (column => value, ...), a numerically indexed array (0 => value, ...), or an object. ( ->column = value ), respectively.  With OBJECT_K, return an associative array of row objects keyed by the value of each row's first column's value.  Duplicate keys are discarded.
  1413 	 * @param string $output Optional. Any of ARRAY_A | ARRAY_N | OBJECT | OBJECT_K constants. With one of the first three, return an array of rows indexed from 0 by SQL result row number.
       
  1414 	 * 	Each row is an associative array (column => value, ...), a numerically indexed array (0 => value, ...), or an object. ( ->column = value ), respectively.
       
  1415 	 * 	With OBJECT_K, return an associative array of row objects keyed by the value of each row's first column's value. Duplicate keys are discarded.
   926 	 * @return mixed Database query results
  1416 	 * @return mixed Database query results
   927 	 */
  1417 	 */
   928 	function get_results($query = null, $output = OBJECT) {
  1418 	function get_results( $query = null, $output = OBJECT ) {
   929 		$this->func_call = "\$db->get_results(\"$query\", $output)";
  1419 		$this->func_call = "\$db->get_results(\"$query\", $output)";
   930 
  1420 
   931 		if ( $query )
  1421 		if ( $query )
   932 			$this->query($query);
  1422 			$this->query( $query );
   933 		else
  1423 		else
   934 			return null;
  1424 			return null;
   935 
  1425 
       
  1426 		$new_array = array();
   936 		if ( $output == OBJECT ) {
  1427 		if ( $output == OBJECT ) {
   937 			// Return an integer-keyed array of row objects
  1428 			// Return an integer-keyed array of row objects
   938 			return $this->last_result;
  1429 			return $this->last_result;
   939 		} elseif ( $output == OBJECT_K ) {
  1430 		} elseif ( $output == OBJECT_K ) {
   940 			// Return an array of row objects with keys from column 1
  1431 			// Return an array of row objects with keys from column 1
   941 			// (Duplicates are discarded)
  1432 			// (Duplicates are discarded)
   942 			foreach ( $this->last_result as $row ) {
  1433 			foreach ( $this->last_result as $row ) {
   943 				$key = array_shift( get_object_vars( $row ) );
  1434 				$var_by_ref = get_object_vars( $row );
   944 				if ( !isset( $new_array[ $key ] ) )
  1435 				$key = array_shift( $var_by_ref );
       
  1436 				if ( ! isset( $new_array[ $key ] ) )
   945 					$new_array[ $key ] = $row;
  1437 					$new_array[ $key ] = $row;
   946 			}
  1438 			}
   947 			return $new_array;
  1439 			return $new_array;
   948 		} elseif ( $output == ARRAY_A || $output == ARRAY_N ) {
  1440 		} elseif ( $output == ARRAY_A || $output == ARRAY_N ) {
   949 			// Return an integer-keyed array of...
  1441 			// Return an integer-keyed array of...
   950 			if ( $this->last_result ) {
  1442 			if ( $this->last_result ) {
   951 				$i = 0;
       
   952 				foreach( (array) $this->last_result as $row ) {
  1443 				foreach( (array) $this->last_result as $row ) {
   953 					if ( $output == ARRAY_N ) {
  1444 					if ( $output == ARRAY_N ) {
   954 						// ...integer-keyed row arrays
  1445 						// ...integer-keyed row arrays
   955 						$new_array[$i] = array_values( get_object_vars( $row ) );
  1446 						$new_array[] = array_values( get_object_vars( $row ) );
   956 					} else {
  1447 					} else {
   957 						// ...column name-keyed row arrays
  1448 						// ...column name-keyed row arrays
   958 						$new_array[$i] = get_object_vars( $row );
  1449 						$new_array[] = get_object_vars( $row );
   959 					}
  1450 					}
   960 					++$i;
       
   961 				}
  1451 				}
   962 				return $new_array;
       
   963 			}
  1452 			}
   964 		}
  1453 			return $new_array;
       
  1454 		}
       
  1455 		return null;
   965 	}
  1456 	}
   966 
  1457 
   967 	/**
  1458 	/**
   968 	 * Retrieve column metadata from the last query.
  1459 	 * Retrieve column metadata from the last query.
   969 	 *
  1460 	 *
   970 	 * @since 0.71
  1461 	 * @since 0.71
   971 	 *
  1462 	 *
   972 	 * @param string $info_type one of name, table, def, max_length, not_null, primary_key, multiple_key, unique_key, numeric, blob, type, unsigned, zerofill
  1463 	 * @param string $info_type Optional. Type one of name, table, def, max_length, not_null, primary_key, multiple_key, unique_key, numeric, blob, type, unsigned, zerofill
   973 	 * @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
  1464 	 * @param int $col_offset Optional. 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
   974 	 * @return mixed Column Results
  1465 	 * @return mixed Column Results
   975 	 */
  1466 	 */
   976 	function get_col_info($info_type = 'name', $col_offset = -1) {
  1467 	function get_col_info( $info_type = 'name', $col_offset = -1 ) {
   977 		if ( $this->col_info ) {
  1468 		if ( $this->col_info ) {
   978 			if ( $col_offset == -1 ) {
  1469 			if ( $col_offset == -1 ) {
   979 				$i = 0;
  1470 				$i = 0;
       
  1471 				$new_array = array();
   980 				foreach( (array) $this->col_info as $col ) {
  1472 				foreach( (array) $this->col_info as $col ) {
   981 					$new_array[$i] = $col->{$info_type};
  1473 					$new_array[$i] = $col->{$info_type};
   982 					$i++;
  1474 					$i++;
   983 				}
  1475 				}
   984 				return $new_array;
  1476 				return $new_array;
   994 	 * @since 1.5.0
  1486 	 * @since 1.5.0
   995 	 *
  1487 	 *
   996 	 * @return true
  1488 	 * @return true
   997 	 */
  1489 	 */
   998 	function timer_start() {
  1490 	function timer_start() {
   999 		$mtime = microtime();
  1491 		$this->time_start = microtime( true );
  1000 		$mtime = explode(' ', $mtime);
       
  1001 		$this->time_start = $mtime[1] + $mtime[0];
       
  1002 		return true;
  1492 		return true;
  1003 	}
  1493 	}
  1004 
  1494 
  1005 	/**
  1495 	/**
  1006 	 * Stops the debugging timer.
  1496 	 * Stops the debugging timer.
  1007 	 *
  1497 	 *
  1008 	 * @since 1.5.0
  1498 	 * @since 1.5.0
  1009 	 *
  1499 	 *
  1010 	 * @return int Total time spent on the query, in milliseconds
  1500 	 * @return float Total time spent on the query, in seconds
  1011 	 */
  1501 	 */
  1012 	function timer_stop() {
  1502 	function timer_stop() {
  1013 		$mtime = microtime();
  1503 		return ( microtime( true ) - $this->time_start );
  1014 		$mtime = explode(' ', $mtime);
       
  1015 		$time_end = $mtime[1] + $mtime[0];
       
  1016 		$time_total = $time_end - $this->time_start;
       
  1017 		return $time_total;
       
  1018 	}
  1504 	}
  1019 
  1505 
  1020 	/**
  1506 	/**
  1021 	 * Wraps errors in a nice header and footer and dies.
  1507 	 * Wraps errors in a nice header and footer and dies.
  1022 	 *
  1508 	 *
  1023 	 * Will not die if wpdb::$show_errors is true
  1509 	 * Will not die if wpdb::$show_errors is true
  1024 	 *
  1510 	 *
  1025 	 * @since 1.5.0
  1511 	 * @since 1.5.0
  1026 	 *
  1512 	 *
  1027 	 * @param string $message The Error message
  1513 	 * @param string $message The Error message
  1028 	 * @param string $error_code (optional) A Computer readable string to identify the error.
  1514 	 * @param string $error_code Optional. A Computer readable string to identify the error.
  1029 	 * @return false|void
  1515 	 * @return false|void
  1030 	 */
  1516 	 */
  1031 	function bail($message, $error_code = '500') {
  1517 	function bail( $message, $error_code = '500' ) {
  1032 		if ( !$this->show_errors ) {
  1518 		if ( !$this->show_errors ) {
  1033 			if ( class_exists('WP_Error') )
  1519 			if ( class_exists( 'WP_Error' ) )
  1034 				$this->error = new WP_Error($error_code, $message);
  1520 				$this->error = new WP_Error($error_code, $message);
  1035 			else
  1521 			else
  1036 				$this->error = $message;
  1522 				$this->error = $message;
  1037 			return false;
  1523 			return false;
  1038 		}
  1524 		}
  1039 		wp_die($message);
  1525 		wp_die($message);
  1040 	}
  1526 	}
  1041 
  1527 
  1042 	/**
  1528 	/**
  1043 	 * Whether or not MySQL database is at least the required minimum version.
  1529 	 * Whether MySQL database is at least the required minimum version.
  1044 	 *
  1530 	 *
  1045 	 * @since 2.5.0
  1531 	 * @since 2.5.0
  1046 	 * @uses $wp_version
  1532 	 * @uses $wp_version
       
  1533 	 * @uses $required_mysql_version
  1047 	 *
  1534 	 *
  1048 	 * @return WP_Error
  1535 	 * @return WP_Error
  1049 	 */
  1536 	 */
  1050 	function check_database_version()
  1537 	function check_database_version() {
  1051 	{
  1538 		global $wp_version, $required_mysql_version;
  1052 		global $wp_version;
  1539 		// Make sure the server has the required MySQL version
  1053 		// Make sure the server has MySQL 4.1.2
  1540 		if ( version_compare($this->db_version(), $required_mysql_version, '<') )
  1054 		if ( version_compare($this->db_version(), '4.1.2', '<') )
  1541 			return new WP_Error('database_version', sprintf( __( '<strong>ERROR</strong>: WordPress %1$s requires MySQL %2$s or higher' ), $wp_version, $required_mysql_version ));
  1055 			return new WP_Error('database_version',sprintf(__('<strong>ERROR</strong>: WordPress %s requires MySQL 4.1.2 or higher'), $wp_version));
  1542 	}
  1056 	}
  1543 
  1057 
  1544 	/**
  1058 	/**
  1545 	 * Whether the database supports collation.
  1059 	 * Whether of not the database supports collation.
       
  1060 	 *
  1546 	 *
  1061 	 * Called when WordPress is generating the table scheme.
  1547 	 * Called when WordPress is generating the table scheme.
  1062 	 *
  1548 	 *
  1063 	 * @since 2.5.0
  1549 	 * @since 2.5.0
  1064 	 *
  1550 	 *
  1067 	function supports_collation() {
  1553 	function supports_collation() {
  1068 		return $this->has_cap( 'collation' );
  1554 		return $this->has_cap( 'collation' );
  1069 	}
  1555 	}
  1070 
  1556 
  1071 	/**
  1557 	/**
  1072 	 * Generic function to determine if a database supports a particular feature
  1558 	 * Determine if a database supports a particular feature
       
  1559 	 *
       
  1560 	 * @since 2.7.0
       
  1561 	 * @see   wpdb::db_version()
       
  1562 	 *
  1073 	 * @param string $db_cap the feature
  1563 	 * @param string $db_cap the feature
  1074 	 * @param false|string|resource $dbh_or_table (not implemented) Which database to test.  False = the currently selected database, string = the database containing the specified table, resource = the database corresponding to the specified mysql resource.
       
  1075 	 * @return bool
  1564 	 * @return bool
  1076 	 */
  1565 	 */
  1077 	function has_cap( $db_cap ) {
  1566 	function has_cap( $db_cap ) {
  1078 		$version = $this->db_version();
  1567 		$version = $this->db_version();
  1079 
  1568 
  1080 		switch ( strtolower( $db_cap ) ) :
  1569 		switch ( strtolower( $db_cap ) ) {
  1081 		case 'collation' :    // @since 2.5.0
  1570 			case 'collation' :    // @since 2.5.0
  1082 		case 'group_concat' : // @since 2.7
  1571 			case 'group_concat' : // @since 2.7
  1083 		case 'subqueries' :   // @since 2.7
  1572 			case 'subqueries' :   // @since 2.7
  1084 			return version_compare($version, '4.1', '>=');
  1573 				return version_compare( $version, '4.1', '>=' );
  1085 			break;
  1574 			case 'set_charset' :
  1086 		endswitch;
  1575 				return version_compare($version, '5.0.7', '>=');
       
  1576 		};
  1087 
  1577 
  1088 		return false;
  1578 		return false;
  1089 	}
  1579 	}
  1090 
  1580 
  1091 	/**
  1581 	/**
  1092 	 * Retrieve the name of the function that called wpdb.
  1582 	 * Retrieve the name of the function that called wpdb.
  1093 	 *
  1583 	 *
  1094 	 * Requires PHP 4.3 and searches up the list of functions until it reaches
  1584 	 * Searches up the list of functions until it reaches
  1095 	 * the one that would most logically had called this method.
  1585 	 * the one that would most logically had called this method.
  1096 	 *
  1586 	 *
  1097 	 * @since 2.5.0
  1587 	 * @since 2.5.0
  1098 	 *
  1588 	 *
  1099 	 * @return string The name of the calling function
  1589 	 * @return string The name of the calling function
  1100 	 */
  1590 	 */
  1101 	function get_caller() {
  1591 	function get_caller() {
  1102 		// requires PHP 4.3+
  1592 		return wp_debug_backtrace_summary( __CLASS__ );
  1103 		if ( !is_callable('debug_backtrace') )
  1593 	}
  1104 			return '';
  1594 
  1105 
  1595 	/**
  1106 		$bt = debug_backtrace();
  1596 	 * The database version number.
  1107 		$caller = array();
  1597 	 *
  1108 
  1598 	 * @since 2.7.0
  1109 		$bt = array_reverse( $bt );
  1599 	 *
  1110 		foreach ( (array) $bt as $call ) {
       
  1111 			if ( @$call['class'] == __CLASS__ )
       
  1112 				continue;
       
  1113 			$function = $call['function'];
       
  1114 			if ( isset( $call['class'] ) )
       
  1115 				$function = $call['class'] . "->$function";
       
  1116 			$caller[] = $function;
       
  1117 		}
       
  1118 		$caller = join( ', ', $caller );
       
  1119 
       
  1120 		return $caller;
       
  1121 	}
       
  1122 
       
  1123 	/**
       
  1124 	 * The database version number
       
  1125 	 * @param false|string|resource $dbh_or_table (not implemented) Which database to test.  False = the currently selected database, string = the database containing the specified table, resource = the database corresponding to the specified mysql resource.
       
  1126 	 * @return false|string false on failure, version number on success
  1600 	 * @return false|string false on failure, version number on success
  1127 	 */
  1601 	 */
  1128 	function db_version() {
  1602 	function db_version() {
  1129 		return preg_replace('/[^0-9.].*/', '', mysql_get_server_info( $this->dbh ));
  1603 		return preg_replace( '/[^0-9.].*/', '', mysql_get_server_info( $this->dbh ) );
  1130 	}
  1604 	}
  1131 }
  1605 }
  1132 
       
  1133 if ( ! isset($wpdb) ) {
       
  1134 	/**
       
  1135 	 * WordPress Database Object, if it isn't set already in wp-content/db.php
       
  1136 	 * @global object $wpdb Creates a new wpdb object based on wp-config.php Constants for the database
       
  1137 	 * @since 0.71
       
  1138 	 */
       
  1139 	$wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
       
  1140 }
       
  1141 ?>