web/wp-includes/wp-db.php
branchwordpress
changeset 132 4d4862461b8d
parent 109 03b0d1493584
equal deleted inserted replaced
131:a4642baaf829 132:4d4862461b8d
   207 	 * @var string
   207 	 * @var string
   208 	 */
   208 	 */
   209 	var $postmeta;
   209 	var $postmeta;
   210 
   210 
   211 	/**
   211 	/**
       
   212 	 * WordPress Comment Metadata table
       
   213 	 *
       
   214 	 * @since 2.9
       
   215 	 * @access public
       
   216 	 * @var string
       
   217 	 */
       
   218 	var $commentmeta;
       
   219 
       
   220 	/**
   212 	 * WordPress User Metadata table
   221 	 * WordPress User Metadata table
   213 	 *
   222 	 *
   214 	 * @since 2.3.0
   223 	 * @since 2.3.0
   215 	 * @access public
   224 	 * @access public
   216 	 * @var string
   225 	 * @var string
   250 	 * @since {@internal Version Unknown}}
   259 	 * @since {@internal Version Unknown}}
   251 	 * @access private
   260 	 * @access private
   252 	 * @var array
   261 	 * @var array
   253 	 */
   262 	 */
   254 	var $tables = array('users', 'usermeta', 'posts', 'categories', 'post2cat', 'comments', 'links', 'link2cat', 'options',
   263 	var $tables = array('users', 'usermeta', 'posts', 'categories', 'post2cat', 'comments', 'links', 'link2cat', 'options',
   255 			'postmeta', 'terms', 'term_taxonomy', 'term_relationships');
   264 			'postmeta', 'terms', 'term_taxonomy', 'term_relationships', 'commentmeta');
       
   265 
       
   266 	/**
       
   267 	 * List of deprecated WordPress tables
       
   268 	 *
       
   269 	 * @since 2.9.0
       
   270 	 * @access private
       
   271 	 * @var array
       
   272 	 */
       
   273 	var $old_tables = array('categories', 'post2cat', 'link2cat');
       
   274 
   256 
   275 
   257 	/**
   276 	/**
   258 	 * Format specifiers for DB columns. Columns not listed here default to %s.  Initialized in wp-settings.php.
   277 	 * Format specifiers for DB columns. Columns not listed here default to %s.  Initialized in wp-settings.php.
   259 	 *
   278 	 *
   260 	 * Keys are colmn names, values are format types: 'ID' => '%d'
   279 	 * Keys are colmn names, values are format types: 'ID' => '%d'
   294 	 * @var bool
   313 	 * @var bool
   295 	 */
   314 	 */
   296 	var $real_escape = false;
   315 	var $real_escape = false;
   297 
   316 
   298 	/**
   317 	/**
       
   318 	 * Database Username
       
   319 	 *
       
   320 	 * @since 2.9.0
       
   321 	 * @access private
       
   322 	 * @var string
       
   323 	 */
       
   324 	var $dbuser;
       
   325 
       
   326 	/**
   299 	 * Connects to the database server and selects a database
   327 	 * Connects to the database server and selects a database
   300 	 *
   328 	 *
   301 	 * PHP4 compatibility layer for calling the PHP5 constructor.
   329 	 * PHP4 compatibility layer for calling the PHP5 constructor.
   302 	 *
   330 	 *
   303 	 * @uses wpdb::__construct() Passes parameters and returns result
   331 	 * @uses wpdb::__construct() Passes parameters and returns result
   327 	 * @param string $dbhost MySQL database host
   355 	 * @param string $dbhost MySQL database host
   328 	 */
   356 	 */
   329 	function __construct($dbuser, $dbpassword, $dbname, $dbhost) {
   357 	function __construct($dbuser, $dbpassword, $dbname, $dbhost) {
   330 		register_shutdown_function(array(&$this, "__destruct"));
   358 		register_shutdown_function(array(&$this, "__destruct"));
   331 
   359 
   332 		if ( defined('WP_DEBUG') and WP_DEBUG == true )
   360 		if ( WP_DEBUG )
   333 			$this->show_errors();
   361 			$this->show_errors();
   334 
   362 
   335 		if ( defined('DB_CHARSET') )
   363 		if ( defined('DB_CHARSET') )
   336 			$this->charset = DB_CHARSET;
   364 			$this->charset = DB_CHARSET;
   337 
   365 
   338 		if ( defined('DB_COLLATE') )
   366 		if ( defined('DB_COLLATE') )
   339 			$this->collate = DB_COLLATE;
   367 			$this->collate = DB_COLLATE;
       
   368 
       
   369 		$this->dbuser = $dbuser;
   340 
   370 
   341 		$this->dbh = @mysql_connect($dbhost, $dbuser, $dbpassword, true);
   371 		$this->dbh = @mysql_connect($dbhost, $dbuser, $dbpassword, true);
   342 		if (!$this->dbh) {
   372 		if (!$this->dbh) {
   343 			$this->bail(sprintf(/*WP_I18N_DB_CONN_ERROR*/'
   373 			$this->bail(sprintf(/*WP_I18N_DB_CONN_ERROR*/'
   344 <h1>Erreur lors de l&rsquo;établissement de la connexion &agrave; la base de données</h1>
   374 <h1>Erreur lors de l&rsquo;établissement de la connexion &agrave; la base de données</h1>
   347 	<li>Êtes-vous certain(e) d&rsquo;avoir correctement indiqué votre identifiant et votre mot de passe&nbsp;?</li>
   377 	<li>Êtes-vous certain(e) d&rsquo;avoir correctement indiqué votre identifiant et votre mot de passe&nbsp;?</li>
   348 	<li>Êtes-vous certain(e) d&rsquo;avoir entré le bon serveur de base de données&nbsp;?</li>
   378 	<li>Êtes-vous certain(e) d&rsquo;avoir entré le bon serveur de base de données&nbsp;?</li>
   349 	<li>Êtes-vous certain(e) que le serveur de base de données fonctionne correctement&nbsp;?</li>
   379 	<li>Êtes-vous certain(e) que le serveur de base de données fonctionne correctement&nbsp;?</li>
   350 </ul>
   380 </ul>
   351 <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>
   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>
   352 '/*/WP_I18N_DB_CONN_ERROR*/, $dbhost));
   382 '/*/WP_I18N_DB_CONN_ERROR*/, $dbhost), 'db_connect_fail');
   353 			return;
   383 			return;
   354 		}
   384 		}
   355 
   385 
   356 		$this->ready = true;
   386 		$this->ready = true;
   357 
   387 
   358 		if ( $this->has_cap( 'collation' ) ) {
   388 		if ( $this->has_cap( 'collation' ) && !empty($this->charset) ) {
   359 			if ( !empty($this->charset) ) {
   389 			if ( function_exists('mysql_set_charset') ) {
   360 				if ( function_exists('mysql_set_charset') ) {
   390 				mysql_set_charset($this->charset, $this->dbh);
   361 					mysql_set_charset($this->charset, $this->dbh);
   391 				$this->real_escape = true;
   362 					$this->real_escape = true;
   392 			} else {
   363 				} else {
   393 				$collation_query = "SET NAMES '{$this->charset}'";
   364 					$collation_query = "SET NAMES '{$this->charset}'";
   394 				if ( !empty($this->collate) )
   365 					if ( !empty($this->collate) )
   395 					$collation_query .= " COLLATE '{$this->collate}'";
   366 						$collation_query .= " COLLATE '{$this->collate}'";
   396 				$this->query($collation_query);
   367 					$this->query($collation_query);
       
   368 				}
       
   369 			}
   397 			}
   370 		}
   398 		}
   371 
   399 
   372 		$this->select($dbname);
   400 		$this->select($dbname);
   373 	}
   401 	}
   434 <ul>
   462 <ul>
   435 <li>Êtes-vous certain(e) qu&rsquo;elle existe&nbsp;?</li>
   463 <li>Êtes-vous certain(e) qu&rsquo;elle existe&nbsp;?</li>
   436 <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>
   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>
   437 <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>
   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>
   438 </ul>
   466 </ul>
   439 <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, DB_USER));
   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');
   440 			return;
   468 			return;
   441 		}
   469 		}
   442 	}
   470 	}
   443 
   471 
   444 	function _weak_escape($string) {
   472 	function _weak_escape($string) {
   994 	 *
  1022 	 *
   995 	 * Will not die if wpdb::$show_errors is true
  1023 	 * Will not die if wpdb::$show_errors is true
   996 	 *
  1024 	 *
   997 	 * @since 1.5.0
  1025 	 * @since 1.5.0
   998 	 *
  1026 	 *
   999 	 * @param string $message
  1027 	 * @param string $message The Error message
       
  1028 	 * @param string $error_code (optional) A Computer readable string to identify the error.
  1000 	 * @return false|void
  1029 	 * @return false|void
  1001 	 */
  1030 	 */
  1002 	function bail($message) {
  1031 	function bail($message, $error_code = '500') {
  1003 		if ( !$this->show_errors ) {
  1032 		if ( !$this->show_errors ) {
  1004 			if ( class_exists('WP_Error') )
  1033 			if ( class_exists('WP_Error') )
  1005 				$this->error = new WP_Error('500', $message);
  1034 				$this->error = new WP_Error($error_code, $message);
  1006 			else
  1035 			else
  1007 				$this->error = $message;
  1036 				$this->error = $message;
  1008 			return false;
  1037 			return false;
  1009 		}
  1038 		}
  1010 		wp_die($message);
  1039 		wp_die($message);
  1019 	 * @return WP_Error
  1048 	 * @return WP_Error
  1020 	 */
  1049 	 */
  1021 	function check_database_version()
  1050 	function check_database_version()
  1022 	{
  1051 	{
  1023 		global $wp_version;
  1052 		global $wp_version;
  1024 		// Make sure the server has MySQL 4.0
  1053 		// Make sure the server has MySQL 4.1.2
  1025 		if ( version_compare($this->db_version(), '4.0.0', '<') )
  1054 		if ( version_compare($this->db_version(), '4.1.2', '<') )
  1026 			return new WP_Error('database_version',sprintf(__('<strong>ERROR</strong>: WordPress %s requires MySQL 4.0.0 or higher'), $wp_version));
  1055 			return new WP_Error('database_version',sprintf(__('<strong>ERROR</strong>: WordPress %s requires MySQL 4.1.2 or higher'), $wp_version));
  1027 	}
  1056 	}
  1028 
  1057 
  1029 	/**
  1058 	/**
  1030 	 * Whether of not the database supports collation.
  1059 	 * Whether of not the database supports collation.
  1031 	 *
  1060 	 *
  1033 	 *
  1062 	 *
  1034 	 * @since 2.5.0
  1063 	 * @since 2.5.0
  1035 	 *
  1064 	 *
  1036 	 * @return bool True if collation is supported, false if version does not
  1065 	 * @return bool True if collation is supported, false if version does not
  1037 	 */
  1066 	 */
  1038 	function supports_collation()
  1067 	function supports_collation() {
  1039 	{
       
  1040 		return $this->has_cap( 'collation' );
  1068 		return $this->has_cap( 'collation' );
  1041 	}
  1069 	}
  1042 
  1070 
  1043 	/**
  1071 	/**
  1044 	 * Generic function to determine if a database supports a particular feature
  1072 	 * Generic function to determine if a database supports a particular feature