+ /**
+ * WordPress Terms table
+ *
+ * @since 2.3.0
+ * @access public
+ * @var string
+ */
+ var $terms;
+
+ /**
+ * WordPress Term Relationships table
+ *
+ * @since 2.3.0
+ * @access public
+ * @var string
+ */
+ var $term_relationships;
+
+ /**
+ * WordPress Term Taxonomy table
+ *
+ * @since 2.3.0
+ * @access public
+ * @var string
+ */
+ var $term_taxonomy;
+
+ /*
+ * Global and Multisite tables
+ */
+
+ /**
+ * WordPress User Metadata table
+ *
+ * @since 2.3.0
+ * @access public
+ * @var string
+ */
+ var $usermeta;
+
+ /**
+ * WordPress Users table
+ *
+ * @since 1.5.0
+ * @access public
+ * @var string
+ */
+ var $users;
+
+ /**
+ * Multisite Blogs table
+ *
+ * @since 3.0.0
+ * @access public
+ * @var string
+ */
+ var $blogs;
+
+ /**
+ * Multisite Blog Versions table
+ *
+ * @since 3.0.0
+ * @access public
+ * @var string
+ */
+ var $blog_versions;
+
+ /**
+ * Multisite Registration Log table
+ *
+ * @since 3.0.0
+ * @access public
+ * @var string
+ */
+ var $registration_log;
+
+ /**
+ * Multisite Signups table
+ *
+ * @since 3.0.0
+ * @access public
+ * @var string
+ */
+ var $signups;
+
+ /**
+ * Multisite Sites table
+ *
+ * @since 3.0.0
+ * @access public
+ * @var string
+ */
+ var $site;
+
+ /**
+ * Multisite Sitewide Terms table
+ *
+ * @since 3.0.0
+ * @access public
+ * @var string
+ */
+ var $sitecategories;
+
+ /**
+ * Multisite Site Metadata table
+ *
+ * @since 3.0.0
+ * @access public
+ * @var string
+ */
+ var $sitemeta;
+
+ /**
+ * Format specifiers for DB columns. Columns not listed here default to %s. Initialized during WP load.
+ *
+ * Keys are column names, values are format types: 'ID' => '%d'
+ *
+ * @since 2.8.0
+ * @see wpdb:prepare()
+ * @see wpdb:insert()
+ * @see wpdb:update()
+ * @see wp_set_wpdb_vars()
+ * @access public
+ * @var array
+ */
+ var $field_types = array();
+
+ /**
+ * Database table columns charset
+ *
+ * @since 2.2.0
+ * @access public
+ * @var string
+ */
+ var $charset;
+
+ /**
+ * Database table columns collate
+ *
+ * @since 2.2.0
+ * @access public
+ * @var string
+ */
+ var $collate;
+
+ /**
+ * Whether to use mysql_real_escape_string
+ *
+ * @since 2.8.0
+ * @access public
+ * @var bool
+ */
+ var $real_escape = false;
+
+ /**
+ * Database Username
+ *
+ * @since 2.9.0
+ * @access private
+ * @var string
+ */
+ var $dbuser;
+
+ /**
+ * A textual description of the last query/get_row/get_var call
+ *
+ * @since 3.0.0
+ * @access public
+ * @var string
+ */
+ var $func_call;
+
+ /**
+ * Connects to the database server and selects a database
+ *
+ * PHP4 compatibility layer for calling the PHP5 constructor.
+ *
+ * @uses wpdb::__construct() Passes parameters and returns result
+ * @since 0.71
+ *
+ * @param string $dbuser MySQL database user
+ * @param string $dbpassword MySQL database password
+ * @param string $dbname MySQL database name
+ * @param string $dbhost MySQL database host
+ */
+ function wpdb( $dbuser, $dbpassword, $dbname, $dbhost ) {
+ return $this->__construct( $dbuser, $dbpassword, $dbname, $dbhost );
+ }
+
+ /**
+ * Connects to the database server and selects a database
+ *
+ * PHP5 style constructor for compatibility with PHP5. Does
+ * the actual setting up of the class properties and connection
+ * to the database.
+ *
+ * @link http://core.trac.wordpress.org/ticket/3354
+ * @since 2.0.8
+ *
+ * @param string $dbuser MySQL database user
+ * @param string $dbpassword MySQL database password
+ * @param string $dbname MySQL database name
+ * @param string $dbhost MySQL database host
+ */
+ function __construct( $dbuser, $dbpassword, $dbname, $dbhost ) {
+ register_shutdown_function( array( &$this, '__destruct' ) );
+
+ if ( WP_DEBUG )
+ $this->show_errors();
+
+ $this->init_charset();
+
+ $this->dbuser = $dbuser;
+ $this->dbpassword = $dbpassword;
+ $this->dbname = $dbname;
+ $this->dbhost = $dbhost;
+
+ $this->db_connect();
+ }
+
+ /**
+ * PHP5 style destructor and will run when database object is destroyed.
+ *
+ * @see wpdb::__construct()
+ * @since 2.0.8
+ * @return bool true
+ */
+ function __destruct() {
+ return true;
+ }
+
+ /**
+ * Set $this->charset and $this->collate
+ *
+ * @since 3.1.0
+ */
+ function init_charset() {
+ if ( function_exists('is_multisite') && is_multisite() ) {
+ $this->charset = 'utf8';
+ if ( defined( 'DB_COLLATE' ) && DB_COLLATE )
+ $this->collate = DB_COLLATE;
+ else
+ $this->collate = 'utf8_general_ci';
+ } elseif ( defined( 'DB_COLLATE' ) ) {
+ $this->collate = DB_COLLATE;
+ }
+
+ if ( defined( 'DB_CHARSET' ) )
+ $this->charset = DB_CHARSET;
+ }
+
+ /**
+ * Sets the connection's character set.
+ *
+ * @since 3.1.0
+ *
+ * @param resource $dbh The resource given by mysql_connect
+ * @param string $charset The character set (optional)
+ * @param string $collate The collation (optional)
+ */
+ function set_charset($dbh, $charset = null, $collate = null) {
+ if ( !isset($charset) )
+ $charset = $this->charset;
+ if ( !isset($collate) )
+ $collate = $this->collate;
+ if ( $this->has_cap( 'collation', $dbh ) && !empty( $charset ) ) {
+ if ( function_exists( 'mysql_set_charset' ) && $this->has_cap( 'set_charset', $dbh ) ) {
+ mysql_set_charset( $charset, $dbh );
+ $this->real_escape = true;
+ } else {
+ $query = $this->prepare( 'SET NAMES %s', $charset );
+ if ( ! empty( $collate ) )
+ $query .= $this->prepare( ' COLLATE %s', $collate );
+ mysql_query( $query, $dbh );
+ }
+ }
+ }
+
+ /**
+ * Sets the table prefix for the WordPress tables.
+ *
+ * @since 2.5.0
+ *
+ * @param string $prefix Alphanumeric name for the new prefix.
+ * @return string|WP_Error Old prefix or WP_Error on error
+ */
+ function set_prefix( $prefix, $set_table_names = true ) {
+
+ if ( preg_match( '|[^a-z0-9_]|i', $prefix ) )
+ return new WP_Error('invalid_db_prefix', /*WP_I18N_DB_BAD_PREFIX*/'Invalid database prefix'/*/WP_I18N_DB_BAD_PREFIX*/);
+
+ $old_prefix = is_multisite() ? '' : $prefix;
+
+ if ( isset( $this->base_prefix ) )
+ $old_prefix = $this->base_prefix;
+
+ $this->base_prefix = $prefix;
+
+ if ( $set_table_names ) {
+ foreach ( $this->tables( 'global' ) as $table => $prefixed_table )
+ $this->$table = $prefixed_table;
+
+ if ( is_multisite() && empty( $this->blogid ) )
+ return $old_prefix;
+
+ $this->prefix = $this->get_blog_prefix();
+
+ foreach ( $this->tables( 'blog' ) as $table => $prefixed_table )
+ $this->$table = $prefixed_table;
+
+ foreach ( $this->tables( 'old' ) as $table => $prefixed_table )
+ $this->$table = $prefixed_table;
+ }
+ return $old_prefix;
+ }
+
+ /**
+ * Sets blog id.
+ *
+ * @since 3.0.0
+ * @access public
+ * @param int $blog_id
+ * @param int $site_id Optional.
+ * @return string previous blog id
+ */
+ function set_blog_id( $blog_id, $site_id = 0 ) {
+ if ( ! empty( $site_id ) )
+ $this->siteid = $site_id;
+
+ $old_blog_id = $this->blogid;
+ $this->blogid = $blog_id;
+
+ $this->prefix = $this->get_blog_prefix();
+
+ foreach ( $this->tables( 'blog' ) as $table => $prefixed_table )
+ $this->$table = $prefixed_table;
+
+ foreach ( $this->tables( 'old' ) as $table => $prefixed_table )
+ $this->$table = $prefixed_table;
+
+ return $old_blog_id;
+ }
+
+ /**
+ * Gets blog prefix.
+ *
+ * @uses is_multisite()
+ * @since 3.0.0
+ * @param int $blog_id Optional.
+ * @return string Blog prefix.
+ */
+ function get_blog_prefix( $blog_id = null ) {
+ if ( is_multisite() ) {
+ if ( null === $blog_id )
+ $blog_id = $this->blogid;
+ if ( defined( 'MULTISITE' ) && ( 0 == $blog_id || 1 == $blog_id ) )
+ return $this->base_prefix;
+ else
+ return $this->base_prefix . $blog_id . '_';
+ } else {
+ return $this->base_prefix;