[bbDev] [1542] trunk: Rename BB_DATABASE_CLASS to
BB_DATABASE_CLASS_INCLUDE (it' s a file).
Sam Bauers
sam at automattic.com
Wed May 21 06:25:34 GMT 2008
Maybe BackPress should use or also include HyperDB...?
We could support 2 configurations. Standard bbPress/WordPress and
HyperDB style configs and just autoswitch between them.
Sam
On 17/05/2008, at 9:08 AM, m at wordpress.org wrote:
> Revision1542AuthormdawaffeDate2008-05-16 23:08:54 +0000 (Fri, 16 May
> 2008)Log Message
> Rename BB_DATABASE_CLASS to BB_DATABASE_CLASS_INCLUDE (it's a file).
>
> Use BB_DATABASE_CLASS to define what DB class will be instantiated.
>
> Remove bbPress' native DB classes. Replace with BackPress DB
> Classes (which are still unstable).
>
> Let's see what breaks. We can always tweak the BP DB classes or go
> back to bb's.
> Modified Paths
> • trunk/bb-settings.php
> Removed Paths
> • trunk/bb-includes/db-mysql.php
> • trunk/bb-includes/db-mysqli.php
> • trunk/bb-includes/db.php
> Diff
> Deleted: trunk/bb-includes/db-mysql.php (1541 => 1542)
> --- trunk/bb-includes/db-mysql.php 2008-05-15 23:17:33 UTC (rev 1541)
> +++ trunk/bb-includes/db-mysql.php 2008-05-16 23:08:54 UTC (rev 1542)
> @@ -1,224 +0,0 @@
> -<?php
> -define( 'BB_MYSQLI', false );
> -
> -class bbdb extends bbdb_base {
> - //
> ==================================================================
> - // DB Constructor - connects to the server and selects a database
> -
> - function bbdb($dbuser, $dbpassword, $dbname, $dbhost) {
> - return $this->__construct($dbuser, $dbpassword, $dbname, $dbhost);
> - }
> -
> - function __construct($dbuser, $dbpassword, $dbname, $dbhost) {
> - return parent::__construct($dbuser, $dbpassword, $dbname, $dbhost);
> - }
> -
> - function __destruct() {
> - return true;
> - }
> -
> - function db_connect( $query = 'SELECT' ) {
> - global $current_connection;
> -
> - if ( empty( $query ) || $query == 'SELECT' )
> - return false;
> -
> - $table = $this->get_table_from_query( $query );
> -
> - $server = new StdClass();
> -
> - global $bb;
> -
> - // We can attempt to force the connection identifier in use
> - if ( $this->_force_dbhname ) {
> - $dbhname = $this->_force_dbhname;
> - }
> -
> - // But sometimes it's not possible to force things
> - if ( !isset($bb->user_bbdb_name) ) {
> - // Always drop back to dbh_local if no custom user database is set
> - $dbhname = 'dbh_local';
> - } elseif ( empty($bb->user_bbdb_name) ) {
> - // Or if it is empty
> - $dbhname = 'dbh_local';
> - } elseif ( $table == $this->users || $table == $this->usermeta ) {
> - // But if they are set and we are querying the user tables then
> always use dbh_user
> - $dbhname = 'dbh_user';
> - }
> -
> - // Now setup the parameters for the connection based on the
> connection identifier
> - switch ($dbhname) {
> - case 'dbh_user':
> - // This can only be forced or set for custom user tables
> - // $dbhname is already set at this stage
> - $server->database = $bb->user_bbdb_name;
> - $server->user = $bb->user_bbdb_user;
> - $server->pass = $bb->user_bbdb_password;
> - $server->host = $bb->user_bbdb_host;
> - $server->charset = $this->user_charset;
> - break;
> - case 'dbh_local':
> - default:
> - // This is the default connection identifier
> - $dbhname = 'dbh_local';
> - $server->database = defined('BBDB_NAME') ?
> constant('BBDB_NAME') : false;
> - $server->user = defined('BBDB_USER') ?
> constant('BBDB_USER') : false;
> - $server->pass = defined('BBDB_PASSWORD') ?
> constant('BBDB_PASSWORD') : false;
> - $server->host = defined('BBDB_HOST') ?
> constant('BBDB_HOST') : false;
> - $server->charset = $this->charset;
> - break;
> - }
> -
> - $current_connection = "$dbhname";
> -
> - if ( isset( $this->$dbhname ) ) // We're already connected!
> - return $this->$dbhname;
> -
> - $this->timer_start();
> -
> - $this->$dbhname = @mysql_connect( $server->host, $server->user,
> $server->pass, true );
> -
> - if (!$this->$dbhname)
> - return false;
> -
> - if ( !empty($server->charset) && $this->has_cap( 'collation',
> $this->$dbhname ) )
> - $this->query("SET NAMES '$server->charset'");
> -
> - if ( !$this->select( $server->database, $this->$dbhname ) ) {
> - unset($this->$dbhname);
> - return false;
> - }
> -
> - $current_connection .= ' connect: ' . number_format( ( $this-
> >timer_stop() * 1000 ), 2) . 'ms';
> -
> - return $this->$dbhname;
> - }
> -
> - //
> ==================================================================
> - // Select a DB (if another one needs to be selected)
> -
> - function select($db, &$dbh) {
> - if (!@mysql_select_db($db, $dbh)) {
> -// $this->handle_error_connecting( $dbh, array( "db" => $db ) );
> - //die('Cannot select DB.');
> - return false;
> - }
> - return true;
> - }
> -
> - //
> ==================================================================
> - // Print SQL/DB error.
> -
> - function print_error($str = '') {
> - global $EZSQL_ERROR;
> - if (!$str) $str = mysql_error();
> - $EZSQL_ERROR[] =
> - array('query' => $this->last_query, 'error_str' => $str);
> -
> - // What to do with the error?
> - switch ( $this->show_errors ) {
> - case 0:
> - // Surpress
> - return false;
> - break;
> -
> - case 1:
> - // Print
> - print "<div id='error'>
> - <p class='bbdberror'><strong>bbPress database error:</strong>
> [$str]<br />
> - <code>$this->last_query</code></p>
> - </div>";
> - return false;
> - break;
> -
> - case 2:
> - // Return
> - return array('query' => $this->last_query, 'error_str' => $str);
> - break;
> - }
> - }
> -
> - //
> ==================================================================
> - // Basic Query - see docs for more detail
> -
> - function query($query) {
> - global $current_connection;
> - // initialise return
> - $return_val = 0;
> - $this->flush();
> -
> - // Log how the function was called
> - $this->func_call = "\$db->query(\"$query\")";
> -
> - // Keep track of the last query for debug..
> - $this->last_query = $query;
> -
> - // Perform the query via std mysql_query function..
> - if (SAVEQUERIES)
> - $this->timer_start();
> -
> - unset( $dbh );
> - $dbh = $this->db_connect( $query );
> -
> - $this->result = @mysql_query($query, $dbh);
> - ++$this->num_queries;
> -
> - if (SAVEQUERIES)
> - $this->queries[] = array( $query . ' server:' .
> $current_connection, $this->timer_stop() );
> -
> - // If there is an error then take note of it..
> - if( $dbh ) {
> - if ( mysql_error( $dbh ) ) {
> - return $this->print_error( mysql_error( $dbh ));
> - }
> - }
> -
> - if ( preg_match("/^\\s*(insert|delete|update|replace|set) /i",
> $query) ) {
> - $this->rows_affected = mysql_affected_rows();
> - // Take note of the insert_id
> - if ( preg_match("/^\\s*(insert|replace) /i",$query) ) {
> - $this->insert_id = mysql_insert_id($dbh);
> - }
> - // Return number of rows affected
> - $return_val = $this->rows_affected;
> - } else {
> - $i = 0;
> - while ($i < @mysql_num_fields($this->result)) {
> - $this->col_info[$i] = @mysql_fetch_field($this->result);
> - $i++;
> - }
> - $num_rows = 0;
> - while ( $row = @mysql_fetch_object($this->result) ) {
> - $this->last_result[$num_rows] = $row;
> - $num_rows++;
> - }
> -
> - @mysql_free_result($this->result);
> -
> - // Log number of rows the query returned
> - $this->num_rows = $num_rows;
> -
> - // Return number of rows selected
> - $return_val = $this->num_rows;
> - }
> -
> - return $return_val;
> - }
> -
> - // table name or mysql resource
> - function db_version( $dbh = false ) {
> - if ( !$dbh )
> - $dbh = $this->forums;
> -
> - if ( !is_resource( $dbh ) )
> - $dbh = $this->db_connect( "DESCRIBE $dbh" );
> -
> - if ( $dbh )
> - return mysql_get_server_info( $dbh );
> - return false;
> - }
> -}
> -
> -if ( !isset($bbdb) )
> - $bbdb = new bbdb(BBDB_USER, BBDB_PASSWORD, BBDB_NAME, BBDB_HOST);
> -?>
> Deleted: trunk/bb-includes/db-mysqli.php (1541 => 1542)
> --- trunk/bb-includes/db-mysqli.php 2008-05-15 23:17:33 UTC (rev 1541)
> +++ trunk/bb-includes/db-mysqli.php 2008-05-16 23:08:54 UTC (rev 1542)
> @@ -1,238 +0,0 @@
> -<?php
> -define( 'BB_MYSQLI', true );
> -
> -class bbdb extends bbdb_base {
> - //
> ==================================================================
> - // DB Constructor - connects to the server and selects a database
> -
> - function bbdb($dbuser, $dbpassword, $dbname, $dbhost) {
> - return $this->__construct($dbuser, $dbpassword, $dbname, $dbhost);
> - }
> -
> - function __construct($dbuser, $dbpassword, $dbname, $dbhost) {
> - return parent::__construct($dbuser, $dbpassword, $dbname, $dbhost);
> - }
> -
> - function __destruct() {
> - return true;
> - }
> -
> - function db_connect( $query = 'SELECT' ) {
> - global $current_connection;
> -
> - if ( empty( $query ) || $query == 'SELECT' )
> - return false;
> -
> - $table = $this->get_table_from_query( $query );
> -
> - $server = new StdClass();
> -
> - global $bb;
> -
> - // We can attempt to force the connection identifier in use
> - if ( $this->_force_dbhname ) {
> - $dbhname = $this->_force_dbhname;
> - }
> -
> - // But sometimes it's not possible to force things
> - if ( !isset($bb->user_bbdb_name) ) {
> - // Always drop back to dbh_local if no custom user database is set
> - $dbhname = 'dbh_local';
> - } elseif ( empty($bb->user_bbdb_name) ) {
> - // Or if it is empty
> - $dbhname = 'dbh_local';
> - } elseif ( $table == $this->users || $table == $this->usermeta ) {
> - // But if they are set and we are querying the user tables then
> always use dbh_user
> - $dbhname = 'dbh_user';
> - }
> -
> - // Now setup the parameters for the connection based on the
> connection identifier
> - switch ($dbhname) {
> - case 'dbh_user':
> - // This can only be forced or set for custom user tables
> - // $dbhname is already set at this stage
> - $server->database = $bb->user_bbdb_name;
> - $server->user = $bb->user_bbdb_user;
> - $server->pass = $bb->user_bbdb_password;
> - $server->host = $bb->user_bbdb_host;
> - $server->port = null;
> - $server->socket = null;
> - $server->charset = $this->user_charset;
> - break;
> - case 'dbh_local':
> - default:
> - // This is the default connection identifier
> - $dbhname = 'dbh_local';
> - $server->database = defined('BBDB_NAME') ?
> constant('BBDB_NAME') : false;
> - $server->user = defined('BBDB_USER') ?
> constant('BBDB_USER') : false;
> - $server->pass = defined('BBDB_PASSWORD') ?
> constant('BBDB_PASSWORD') : false;
> - $server->host = defined('BBDB_HOST') ?
> constant('BBDB_HOST') : false;
> - $server->port = null;
> - $server->socket = null;
> - $server->charset = $this->charset;
> - break;
> - }
> -
> - // Set the port if it is specified in the host
> - if (strpos($server->host, ':') !== false) {
> - list($server->host, $server->port) = explode(':', $server->host);
> - // Make it a socket if it's not numeric
> - if (!is_numeric($server->port)) {
> - $server->socket = $server->port;
> - $server->port = null;
> - }
> - }
> -
> - $current_connection = "$dbhname";
> -
> - if ( isset( $this->$dbhname ) ) // We're already connected!
> - return $this->$dbhname;
> -
> - $this->timer_start();
> -
> - $this->$dbhname = @mysqli_connect( $server->host, $server->user,
> $server->pass, null, $server->port, $server->socket );
> -
> - if (!$this->$dbhname)
> - return false;
> -
> - if ( isset($server->charset) && !empty($server->charset) && $this-
> >has_cap( 'collation', $this->$dbhname ) )
> - $this->query("SET NAMES '$server->charset'");
> -
> - if ( !$this->select( $server->database, $this->$dbhname ) ) {
> - unset($this->$dbhname);
> - return false;
> - }
> -
> - $current_connection .= ' connect: ' . number_format( ( $this-
> >timer_stop() * 1000 ), 2) . 'ms';
> -
> - return $this->$dbhname;
> - }
> -
> - //
> ==================================================================
> - // Select a DB (if another one needs to be selected)
> -
> - function select($db, &$dbh) {
> - if (!@mysqli_select_db($dbh, $db)) {
> -// $this->handle_error_connecting( $dbh, array( "db" => $db ) );
> - //die('Cannot select DB.');
> - return false;
> - }
> - return true;
> - }
> -
> - //
> ==================================================================
> - // Print SQL/DB error.
> -
> - function print_error($str = '') {
> - global $EZSQL_ERROR;
> - if (!$str) $str = mysqli_error( $this->db_connect( $this-
> >last_query ) ); // Will this work?
> - $EZSQL_ERROR[] =
> - array('query' => $this->last_query, 'error_str' => $str);
> -
> - // What to do with the error?
> - switch ( $this->show_errors ) {
> - case 0:
> - // Surpress
> - return false;
> - break;
> -
> - case 1:
> - // Print
> - print "<div id='error'>
> - <p class='bbdberror'><strong>bbPress database error:</strong>
> [$str]<br />
> - <code>$this->last_query</code></p>
> - </div>";
> - return false;
> - break;
> -
> - case 2:
> - // Return
> - return array('query' => $this->last_query, 'error_str' => $str);
> - break;
> - }
> - }
> -
> - //
> ==================================================================
> - // Basic Query - see docs for more detail
> -
> - function query($query) {
> - global $current_connection;
> - // initialise return
> - $return_val = 0;
> - $this->flush();
> -
> - // Log how the function was called
> - $this->func_call = "\$db->query(\"$query\")";
> -
> - // Keep track of the last query for debug..
> - $this->last_query = $query;
> -
> - // Perform the query via std mysqli_query function..
> - if (SAVEQUERIES)
> - $this->timer_start();
> -
> - unset( $dbh );
> - $dbh = $this->db_connect( $query );
> -
> - $this->result = @mysqli_query($dbh, $query);
> - ++$this->num_queries;
> -
> - if (SAVEQUERIES)
> - $this->queries[] = array( $query . ' server:' .
> $current_connection, $this->timer_stop() );
> -
> - // If there is an error then take note of it..
> - if( $dbh ) {
> - if ( mysqli_error( $dbh ) ) {
> - return $this->print_error( mysqli_error( $dbh ) );
> - }
> - }
> -
> - if ( preg_match("/^\\s*(insert|delete|update|replace|set) /i",
> $query) ) {
> - $this->rows_affected = mysqli_affected_rows( $dbh );
> - // Take note of the insert_id
> - if ( preg_match("/^\\s*(insert|replace) /i",$query) ) {
> - $this->insert_id = mysqli_insert_id($dbh);
> - }
> - // Return number of rows affected
> - $return_val = $this->rows_affected;
> - } else {
> - $i = 0;
> - while ($i < @mysqli_num_fields($this->result)) {
> - $this->col_info[$i] = @mysqli_fetch_field($this->result);
> - $i++;
> - }
> - $num_rows = 0;
> - while ( $row = @mysqli_fetch_object($this->result) ) {
> - $this->last_result[$num_rows] = $row;
> - $num_rows++;
> - }
> -
> - @mysqli_free_result($this->result);
> -
> - // Log number of rows the query returned
> - $this->num_rows = $num_rows;
> -
> - // Return number of rows selected
> - $return_val = $this->num_rows;
> - }
> -
> - return $return_val;
> - }
> -
> - // table name or mysqli object
> - function db_version( $dbh = false ) {
> - if ( !$dbh )
> - $dbh = $this->forums;
> -
> - if ( !is_object( $dbh ) )
> - $dbh = $this->db_connect( "DESCRIBE $dbh" );
> -
> - if ( $dbh )
> - return mysqli_get_server_info( $dbh );
> - return false;
> - }
> -}
> -
> -if ( !isset($bbdb) )
> - $bbdb = new bbdb(BBDB_USER, BBDB_PASSWORD, BBDB_NAME, BBDB_HOST);
> -?>
> Deleted: trunk/bb-includes/db.php (1541 => 1542)
> --- trunk/bb-includes/db.php 2008-05-15 23:17:33 UTC (rev 1541)
> +++ trunk/bb-includes/db.php 2008-05-16 23:08:54 UTC (rev 1542)
> @@ -1,544 +0,0 @@
> -<?php
> -define('OBJECT', 'OBJECT', true);
> -define('ARRAY_A', 'ARRAY_A', false);
> -define('ARRAY_N', 'ARRAY_N', false);
> -
> -if ( !defined('SAVEQUERIES') )
> - define('SAVEQUERIES', false);
> -
> -class bbdb_base {
> - var $show_errors = 1;
> - var $num_queries = 0;
> - var $retries = 0;
> - var $last_query;
> - var $col_info;
> - var $queries;
> -
> - var $prefix;
> -
> - // Our tables
> - var $tables = array(
> - 'forums',
> - 'meta',
> - 'posts',
> - 'tagged',
> - 'tags',
> - 'terms',
> - 'term_relationships',
> - 'term_taxonomy',
> - 'topics',
> - 'topicmeta',
> - 'users',
> - 'usermeta'
> - );
> - var $forums;
> - var $meta;
> - var $posts;
> - var $tagged;
> - var $tags;
> - var $terms;
> - var $term_relationships;
> - var $term_taxonomy;
> - var $topics;
> - var $topicmeta;
> - var $users;
> - var $usermeta;
> -
> - var $_force_dbhname = false;
> -
> - var $charset;
> - var $collate;
> -
> - var $user_charset;
> -
> - //
> ==================================================================
> - // DB Constructor - connects to the server and selects a database
> -
> - function bbdb($dbuser, $dbpassword, $dbname, $dbhost) {
> - return $this->__construct($dbuser, $dbpassword, $dbname, $dbhost);
> - }
> -
> - function __construct($dbuser, $dbpassword, $dbname, $dbhost) {
> - if ( defined('BBDB_CHARSET') )
> - $this->charset = BBDB_CHARSET;
> - if ( defined('BBDB_COLLATE') )
> - $this->collate = BBDB_COLLATE;
> -
> - $this->db_connect();
> - return true;
> -
> - }
> -
> - function __destruct() {
> - return true;
> - }
> -
> - function set_prefix($prefix, $tables = FALSE) {
> -
> - // Check that the prefix is valid
> - if ( preg_match('|[^a-z0-9_]|i', $prefix) )
> - return new WP_Error('invalid_db_prefix', 'Invalid database
> prefix (' . $prefix . ')'); // No gettext here
> -
> - if ( !$tables ) {
> - // Set the old prefix to return
> - $old_prefix = $this->prefix;
> - // Set the general prefix
> - $this->prefix = $prefix;
> - // Process all table names
> - $_tables = $this->tables;
> - } elseif ( $prefix ) {
> - $old_prefix = '';
> - // Just process the specified table names
> - $_tables = $tables;
> - } else {
> - return FALSE;
> - }
> -
> - // Add the prefix to the stored table names
> - foreach ( $_tables as $table )
> - $this->$table = $prefix . $table;
> -
> - // Return the old prefix
> - return $old_prefix;
> - }
> -
> - function db_connect( $query = 'SELECT' ) {
> - return false;
> - }
> -
> - function get_table_from_query ( $q ) {
> - If( substr( $q, -1 ) == ';' )
> - $q = substr( $q, 0, -1 );
> - if ( preg_match('/^\s*SELECT.*?\s+FROM\s+`?(\w+)`?\s*/is', $q,
> $maybe) )
> - return $maybe[1];
> - if ( preg_match('/^\s*UPDATE IGNORE\s+`?(\w+)`?\s*/is', $q,
> $maybe) )
> - return $maybe[1];
> - if ( preg_match('/^\s*UPDATE\s+`?(\w+)`?\s*/is', $q, $maybe) )
> - return $maybe[1];
> - if ( preg_match('/^\s*INSERT INTO\s+`?(\w+)`?\s*/is', $q, $maybe) )
> - return $maybe[1];
> - if ( preg_match('/^\s*REPLACE INTO\s+`?(\w+)`?\s*/is', $q,
> $maybe) )
> - return $maybe[1];
> - if ( preg_match('/^\s*INSERT IGNORE INTO\s+`?(\w+)`?\s*/is', $q,
> $maybe) )
> - return $maybe[1];
> - if ( preg_match('/^\s*REPLACE INTO\s+`?(\w+)`?\s*/is', $q,
> $maybe) )
> - return $maybe[1];
> - if ( preg_match('/^\s*DELETE\s+FROM\s+`?(\w+)`?\s*/is', $q,
> $maybe) )
> - return $maybe[1];
> - if ( preg_match('/^\s*(?:TRUNCATE|RENAME|OPTIMIZE|LOCK|UNLOCK)\s
> +TABLE\s+`?(\w+)`?\s*/is', $q, $maybe) )
> - return $maybe[1];
> - if ( preg_match('/^SHOW TABLE STATUS (LIKE|FROM) \'?`?(\w+)\'?`?
> \s*/is', $q, $maybe) )
> - return $maybe[1];
> - if ( preg_match('/^SHOW INDEX FROM `?(\w+)`?\s*/is', $q, $maybe) )
> - return $maybe[1];
> - if ( preg_match('/^\s*CREATE\s+TABLE\s+IF\s+NOT\s+EXISTS\s+`?(\w
> +)`?\s*/is', $q, $maybe) )
> - return $maybe[1];
> - if ( preg_match('/^\s*SHOW CREATE TABLE `?(\w+?)`?\s*/is', $q,
> $maybe) )
> - return $maybe[1];
> - if ( preg_match('/^SHOW CREATE TABLE (wp_[a-z0-9_]+)/is', $q,
> $maybe) )
> - return $maybe[1];
> - if ( preg_match('/^\s*CREATE\s+TABLE\s+`?(\w+)`?\s*/is', $q,
> $maybe) )
> - return $maybe[1];
> - if ( preg_match('/^\s*DROP\s+TABLE\s+IF\s+EXISTS\s+`?(\w+)`?\s*/
> is', $q, $maybe) )
> - return $maybe[1];
> - if ( preg_match('/^\s*DROP\s+TABLE\s+`?(\w+)`?\s*/is', $q,
> $maybe) )
> - return $maybe[1];
> - if ( preg_match('/^\s*DESCRIBE\s+`?(\w+)`?\s*/is', $q, $maybe) )
> - return $maybe[1];
> - if ( preg_match('/^\s*ALTER\s+TABLE\s+`?(\w+)`?\s*/is', $q,
> $maybe) )
> - return $maybe[1];
> - if ( preg_match('/^\s*SELECT.*?\s+FOUND_ROWS\(\)/is', $q) )
> - return $this->last_table;
> -
> - return '';
> - }
> -
> - function is_write_query( $q ) {
> - If( substr( $q, -1 ) == ';' )
> - $q = substr( $q, 0, -1 );
> - if ( preg_match('/^\s*SELECT.*?\s+FROM\s+`?(\w+)`?\s*/is', $q,
> $maybe) )
> - return false;
> - if ( preg_match('/^\s*SHOW DATABASES\s*/is', $q, $maybe) )
> - return false;
> - if ( preg_match('/^\s*UPDATE\s+`?(\w+)`?\s*/is', $q, $maybe) )
> - return true;
> - if ( preg_match('/^\s*INSERT INTO\s+`?(\w+)`?\s*/is', $q, $maybe) )
> - return true;
> - if ( preg_match('/^\s*REPLACE INTO\s+`?(\w+)`?\s*/is', $q,
> $maybe) )
> - return true;
> - if ( preg_match('/^\s*INSERT IGNORE INTO\s+`?(\w+)`?\s*/is', $q,
> $maybe) )
> - return true;
> - if ( preg_match('/^\s*DELETE\s+FROM\s+`?(\w+)`?\s*/is', $q,
> $maybe) )
> - return true;
> - if ( preg_match('/^\s*OPTIMIZE\s+TABLE\s+`?(\w+)`?\s*/is', $q,
> $maybe) )
> - return true;
> - if ( preg_match('/^SHOW TABLE STATUS (LIKE|FROM) \'?`?(\w+)\'?`?
> \s*/is', $q, $maybe) )
> - return true;
> - if ( preg_match('/^\s*CREATE\s+TABLE\s+`?(\w+)`?\s*/is', $q,
> $maybe) )
> - return true;
> - if ( preg_match('/^\s*SHOW CREATE TABLE `?(\w+?)`?.*/is', $q,
> $maybe) )
> - return true;
> - if ( preg_match('/^\s*DROP\s+TABLE\s+`?(\w+)`?\s*/is', $q,
> $maybe) )
> - return true;
> - if ( preg_match('/^\s*DROP\s+TABLE\s+IF\s+EXISTS\s+`?(\w+)`?\s*/
> is', $q, $maybe) )
> - return true;
> - if ( preg_match('/^\s*ALTER\s+TABLE\s+`?(\w+)`?\s*/is', $q,
> $maybe) )
> - return $maybe[1];
> - if ( preg_match('/^\s*DESCRIBE\s+`?(\w+)`?\s*/is', $q, $maybe) )
> - return $maybe[1];
> - if ( preg_match('/^\s*SHOW\s+INDEX\s+FROM\s+`?(\w+)`?\s*/is', $q,
> $maybe) )
> - return $maybe[1];
> - if ( preg_match('/^\s*SELECT.*?\s+FOUND_ROWS\(\)/is', $q) )
> - return false;
> - if ( preg_match('/^\s*RENAME\s+TABLE\s+/i', $q) )
> - return true;
> - if ( preg_match('/^\s*TRUNCATE\s|TABLE\s+/i', $q) )
> - return true;
> - error_log( date( "Y-m-d H:i:s" ) . " is_write: " . $q ."\n\n", 3,
> "/tmp/db-missed.txt" );
> - return true;
> - }
> -
> - //
> ==================================================================
> - // Select a DB (if another one needs to be selected)
> -
> - function select($db, &$dbh) {
> - return false;
> - }
> -
> - //
> ====================================================================
> - // Format a string correctly for safe insert under all PHP
> conditions
> -
> - function escape($str) {
> - return addslashes($str);
> - }
> -
> - function escape_deep( $array ) {
> - return is_array($array) ? array_map(array(&$this, 'escape_deep'),
> $array) : $this->escape( $array );
> - }
> -
> - /**
> - * Escapes content by reference for insertion into the database,
> for security
> - * @param string $s
> - */
> - function escape_by_ref(&$s) {
> - $s = $this->escape($s);
> - }
> -
> - /**
> - * Prepares a SQL query for safe use, using sprintf() syntax
> - */
> - function prepare($args=NULL) {
> - if ( NULL === $args )
> - return;
> - $args = func_get_args();
> - $query = array_shift($args);
> - $query = str_replace("'%s'", '%s', $query); // in case someone
> mistakenly already singlequoted it
> - $query = str_replace('"%s"', '%s', $query); // doublequote
> unquoting
> - $query = str_replace('%s', "'%s'", $query); // quote the strings
> - array_walk($args, array(&$this, 'escape_by_ref'));
> - return @vsprintf($query, $args);
> - }
> -
> - //
> ==================================================================
> - // Print SQL/DB error.
> -
> - function print_error($str = '') {
> - return false;
> - }
> -
> - //
> ==================================================================
> - // Toggle error handling..
> -
> - // Cause errors to be returned in print_error
> - function return_errors() {
> - $this->show_errors = 2;
> - }
> -
> - // Cause errors to be echoed in print_error
> - function show_errors() {
> - $this->show_errors = 1;
> - }
> -
> - // Cause errors to be surpressed in print_error
> - function hide_errors() {
> - $this->show_errors = 0;
> - }
> -
> - //
> ==================================================================
> - // Kill cached query results
> -
> - function flush() {
> - $this->last_result = null;
> - $this->col_info = null;
> - $this->last_query = null;
> - }
> -
> - /**
> - * Insert an array of data into a table
> - * @param string $table WARNING: not sanitized!
> - * @param array $data should not already be SQL-escaped
> - * @return mixed results of $this->query()
> - */
> - function insert($table, $data) {
> - $data = $this->escape_deep($data);
> - $fields = array_keys($data);
> - return $this->query("INSERT INTO $table (`" . implode('`,`',
> $fields) . "`) VALUES ('".implode("','",$data)."')");
> - }
> -
> - /**
> - * Update a row in the table with an array of data
> - * @param string $table WARNING: not sanitized!
> - * @param array $data should not already be SQL-escaped
> - * @param array $where a named array of WHERE column => value
> relationships. Multiple member pairs will be joined with ANDs.
> WARNING: the column names are not currently sanitized!
> - * @return mixed results of $this->query()
> - */
> - function update($table, $data, $where){
> - $data = $this->escape_deep($data);
> - $bits = $wheres = array();
> - foreach ( array_keys($data) as $k )
> - $bits[] = "`$k` = '$data[$k]'";
> -
> - if ( is_array( $where ) )
> - foreach ( $where as $c => $v )
> - $wheres[] = "$c = '" . $this->escape( $v ) . "'";
> - else
> - return false;
> - return $this->query( "UPDATE $table SET " . implode( ', ',
> $bits ) . ' WHERE ' . implode( ' AND ', $wheres ) . ' LIMIT 1' );
> - }
> -
> - //
> ==================================================================
> - // Basic Query - see docs for more detail
> -
> - function query($query) {
> - return false;
> - }
> -
> - //
> ==================================================================
> - // Get one variable from the DB - see docs for more detail
> -
> - function get_var($query=null, $x = 0, $y = 0) {
> - $this->func_call = "\$db->get_var(\"$query\",$x,$y)";
> - if ( $query )
> - $this->query($query);
> -
> - // Extract var out of cached results based x,y vals
> - if ( $this->last_result[$y] ) {
> - $values = array_values(get_object_vars($this->last_result[$y]));
> - }
> -
> - // If there is a value return it else return null
> - return (isset($values[$x]) && $values[$x]!=='') ? $values[$x] :
> null;
> - }
> -
> - //
> ==================================================================
> - // Get one row from the DB - see docs for more detail
> -
> - function get_row($query = null, $output = OBJECT, $y = 0) {
> - $this->func_call = "\$db->get_row(\"$query\",$output,$y)";
> - if ( $query )
> - $this->query($query);
> -
> - if ( $output == OBJECT ) {
> - return $this->last_result[$y] ? $this->last_result[$y] : null;
> - } elseif ( $output == ARRAY_A ) {
> - return $this->last_result[$y] ? get_object_vars($this-
> >last_result[$y]) : null;
> - } elseif ( $output == ARRAY_N ) {
> - return $this->last_result[$y] ?
> array_values(get_object_vars($this->last_result[$y])) : null;
> - } else {
> - return $this->print_error(" \$db->get_row(string query, output
> type, int offset) -- Output type must be one of: OBJECT, ARRAY_A,
> ARRAY_N");
> - }
> - }
> -
> - //
> ==================================================================
> - // Function to get 1 column from the cached result set based in X
> index
> - // se docs for usage and info
> -
> - function get_col($query = null , $x = 0) {
> - if ( $query )
> - $this->query($query);
> -
> - // Extract the column values
> - for ( $i=0; $i < count($this->last_result); $i++ ) {
> - $new_array[$i] = $this->get_var(null, $x, $i);
> - }
> - return $new_array;
> - }
> -
> - //
> ==================================================================
> - // Return the the query as a result set - see docs for more details
> -
> - function get_results($query = null, $output = OBJECT) {
> - $this->func_call = "\$db->get_results(\"$query\", $output)";
> -
> - if ( $query )
> - $this->query($query);
> -
> - // Send back array of objects. Each row is an object
> - if ( $output == OBJECT ) {
> - return $this->last_result;
> - } elseif ( $output == ARRAY_A || $output == ARRAY_N ) {
> - if ( $this->last_result ) {
> - $i = 0;
> - foreach( $this->last_result as $row ) {
> - $new_array[$i] = (array) $row;
> - if ( $output == ARRAY_N ) {
> - $new_array[$i] = array_values($new_array[$i]);
> - }
> - $i++;
> - }
> - return $new_array;
> - } else {
> - return null;
> - }
> - }
> - }
> -
> -
> - //
> ==================================================================
> - // Function to get column meta data info pertaining to the last
> query
> - // see docs for more info and usage
> -
> - function get_col_info($info_type = 'name', $col_offset = -1) {
> - if ( $this->col_info ) {
> - if ( $col_offset == -1 ) {
> - $i = 0;
> - foreach($this->col_info as $col ) {
> - $new_array[$i] = $col->{$info_type};
> - $i++;
> - }
> - return $new_array;
> - } else {
> - return $this->col_info[$col_offset]->{$info_type};
> - }
> - }
> - }
> -
> - function timer_start() {
> - $mtime = microtime();
> - $mtime = explode(' ', $mtime);
> - $this->time_start = $mtime[1] + $mtime[0];
> - return true;
> - }
> -
> - function timer_stop($precision = 3) {
> - $mtime = microtime();
> - $mtime = explode(' ', $mtime);
> - $time_end = $mtime[1] + $mtime[0];
> - $time_total = $time_end - $this->time_start;
> - return $time_total;
> - }
> -
> - function bail($message) { // Just wraps errors in a nice header
> and footer
> - if ( !$this->show_errors )
> - return false;
> - echo <<<HEAD
> - <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd
> ">
> - <html xmlns="http://www.w3.org/1999/xhtml">
> - <head>
> - <meta http-equiv="Content-Type" content="text/html;
> charset=utf-8" />
> - <title>bbPress › Error</title>
> - <style media="screen" type="text/css">
> - <!--
> - html {
> - background: #eee;
> - }
> - body {
> - background: #fff;
> - color: #000;
> - font-family: Georgia, "Times New Roman", Times, serif;
> - margin-left: 25%;
> - margin-right: 25%;
> - padding: .2em 2em;
> - }
> -
> - h1 {
> - color: #006;
> - font-size: 18px;
> - font-weight: lighter;
> - }
> -
> - h2 {
> - font-size: 16px;
> - }
> -
> - p, li, dt {
> - line-height: 140%;
> - padding-bottom: 2px;
> - }
> -
> - ul, ol {
> - padding: 5px 5px 5px 20px;
> - }
> - #logo {
> - margin-bottom: 2em;
> - }
> - -->
> - </style>
> - </head>
> - <body>
> - <h1 id="logo"><img alt="bbPress" src="http://bbpress.org/
> bbpress.png" /></h1>
> -HEAD;
> - echo $message;
> - echo "</body></html>";
> - die();
> - }
> -
> - /**
> - * Checks wether of not the database version is high enough to
> support the features WordPress uses
> - * @global $wp_version
> - */
> - function check_database_version() {
> - $bb_version = function_exists( 'bb_get_option' ) ?
> bb_get_option( 'bb_version' ) : '';
> - // Make sure the server has MySQL 4.0
> - $mysql_version = $this->db_version();
> - if ( version_compare($mysql_version, '4.0.0', '<') )
> - return new
> WP_Error('database_version',sprintf(__('<strong>ERROR</strong>:
> bbPress %s requires MySQL 4.0.0 or higher'), $bb_version));
> - }
> -
> - function has_cap( $db_cap, $dbh_or_table = false ) {
> - $version = $this->db_version( $dbh_or_table );
> -
> - $db_cap = strtolower( $db_cap );
> -
> - switch ( $db_cap ) :
> - case 'group_concat' :
> - case 'collation' :
> - return version_compare($version, '4.1', '>=');
> - break;
> - endswitch;
> -
> - return false;
> - }
> -
> - // table name or mysql resource
> - function db_version( $dbh = false ) {
> - return false;
> - }
> -}
> -
> -
> -// Default database extension is mysql
> -if (!defined('BBDB_EXTENSION')) {
> - define('BBDB_EXTENSION', 'mysql');
> -}
> -
> -// Choose a database extension
> -switch (BBDB_EXTENSION) {
> - case 'mysqli':
> - if (extension_loaded('mysqli')) {
> - require(BB_PATH . BB_INC . 'db-mysqli.php');
> - }
> - break;
> - case 'mysql':
> - if (extension_loaded('mysql')) {
> - require(BB_PATH . BB_INC . 'db-mysql.php');
> - }
> - break;
> -}
> -
> -// Die if object was not created
> -if (!is_object($bbdb)) {
> - die('Your PHP installation appears to be missing the specified
> MySQL extension (' . BBDB_EXTENSION . ') which is required for
> bbPress.');
> -}
> -
> -?>
> Modified: trunk/bb-settings.php (1541 => 1542)
> --- trunk/bb-settings.php 2008-05-15 23:17:33 UTC (rev 1541)
> +++ trunk/bb-settings.php 2008-05-16 23:08:54 UTC (rev 1542)
> @@ -57,12 +57,45 @@
> // Define the include path
> define('BB_INC', 'bb-includes/');
>
> +if ( !defined( 'BACKPRESS_PATH' ) )
> + define( 'BACKPRESS_PATH', BB_PATH . BB_INC . 'backpress/' );
> +require( BACKPRESS_PATH . 'functions.core.php' );
> +require( BACKPRESS_PATH . 'functions.compat.php' );
> +
> // Define the full path to the database class
> -if ( !defined('BB_DATABASE_CLASS') )
> - define('BB_DATABASE_CLASS', BB_PATH . BB_INC . 'db.php');
> +if ( !defined('BB_DATABASE_CLASS_INCLUDE') )
> + define('BB_DATABASE_CLASS_INCLUDE', BACKPRESS_PATH . 'class.bpdb-
> multi.php' );
> // Load the database class
> -require( BB_DATABASE_CLASS );
> +require( BB_DATABASE_CLASS_INCLUDE );
>
> +if ( !defined( 'BB_DATABASE_CLASS' ) )
> + define( 'BB_DATABASE_CLASS', 'BPDB_Multi' );
> +$bbdb_class = BB_DATABASE_CLASS;
> +
> +$bbdb =& new $bbdb_class( array(
> + 'name' => BBDB_NAME,
> + 'user' => BBDB_USER,
> + 'password' => BBDB_PASSWORD,
> + 'host' => BBDB_HOST,
> + 'charset' => defined( 'BBDB_CHARSET' ) ? BBDB_CHARSET : false,
> + 'collate' => defined( 'BBDB_COLLATE' ) ? BBDB_COLLATE : false
> +) );
> +$bbdb->tables = array( // Better way to do this?
> + 'forums',
> + 'meta',
> + 'posts',
> + 'tagged',
> + 'tags',
> + 'terms',
> + 'term_relationships',
> + 'term_taxonomy',
> + 'topics',
> + 'topicmeta'
> +// , 'users' // intentionally left off so that $bbdb->set_prefix
> doesn't have to keep track of stomping them
> +// , 'usermeta // good idea?
> +);
> +unset($bbdb_class);
> +
> // Define the language file directory
> if ( !defined('BB_LANG_DIR') )
> if ( defined('BBLANGDIR') ) // User has set old constant
> @@ -70,12 +103,7 @@
> else
> define('BB_LANG_DIR', BB_PATH . BB_INC . 'languages/'); //
> absolute path with trailing slash
>
> -if ( !defined( 'BACKPRESS_PATH' ) )
> - define( 'BACKPRESS_PATH', BB_PATH . BB_INC . 'backpress/' );
> -
> // Include functions
> -require( BACKPRESS_PATH . 'functions.core.php' );
> -require( BACKPRESS_PATH . 'functions.compat.php' );
> require( BB_PATH . BB_INC . 'wp-functions.php');
> require( BB_PATH . BB_INC . 'functions.php');
> require( BB_PATH . BB_INC . 'classes.php');
> @@ -118,6 +146,7 @@
>
> if ( is_wp_error( $bbdb->set_prefix( $bb_table_prefix ) ) )
> die(__('Your table prefix may only contain letters, numbers and
> underscores.'));
> +$bbdb->set_prefix( $bb_table_prefix, array( 'users', 'usermeta' ) );
>
> if ( defined( 'BB_AWESOME_INCLUDE' ) &&
> file_exists( BB_AWESOME_INCLUDE ) )
> require( BB_AWESOME_INCLUDE );
> @@ -270,6 +299,10 @@
> if ( defined('USER_BBDB_CHARSET') ) // User has set old constant
> $bb->user_bbdb_charset = USER_BBDB_CHARSET;
>
> +if ( !$bb->user_bbdb_collate = bb_get_option('user_bbdb_collate') )
> + if ( defined('USER_BBDB_COLLATE') ) // User has set old constant
> + $bb->user_bbdb_collate = USER_BBDB_COLLATE;
> +
> if ( !$bb->custom_user_table = bb_get_option('custom_user_table') )
> if ( defined('CUSTOM_USER_TABLE') ) // User has set old constant
> $bb->custom_user_table = CUSTOM_USER_TABLE;
> @@ -281,10 +314,6 @@
> if ( is_wp_error( $bbdb->set_prefix( $bb->wp_table_prefix,
> array('users', 'usermeta') ) ) )
> die(__('Your user table prefix may only contain letters, numbers
> and underscores.'));
>
> -// Set the user table's character set if defined
> -if ( isset($bb->user_bbdb_charset) && $bb->user_bbdb_charset )
> - $bbdb->user_charset = $bb->user_bbdb_charset;
> -
> // Set the user table's custom name if defined
> if ( isset($bb->custom_user_table) && $bb->custom_user_table )
> $bbdb->users = $bb->custom_user_table;
> @@ -293,6 +322,19 @@
> if ( isset($bb->custom_user_meta_table) && $bb-
> >custom_user_meta_table )
> $bbdb->usermeta = $bb->custom_user_meta_table;
>
> +if ( $bb->user_bbdb_name ) {
> + $bbdb->add_db_server( 'dbh_user', array(
> + 'name' => $bb->user_bbdb_name,
> + 'user' => $bb->user_bbdb_user,
> + 'password' => $bb->user_bbdb_password,
> + 'host' => $bb->user_bbdb_host,
> + 'charset' => $bb->user_bbdb_charset,
> + 'collate' => $bb->user_bbdb_collate
> + ) );
> + $bbdb->add_db_table( 'dbh_user', $bbdb->users );
> + $bbdb->add_db_table( 'dbh_user', $bbdb->usermeta );
> +}
> +
> // Sort out cookies so they work with WordPress (if required)
> // Note that database integration is no longer a pre-requisite for
> cookie integration
> $bb->wp_siteurl = bb_get_option('wp_siteurl');
> @@ -507,5 +549,3 @@
> $page = bb_get_uri_page();
>
> bb_send_headers();
> -
> -?>
> _______________________________________________
> bbDev mailing list
> bbDev at lists.bbpress.org
> http://lists.bbpress.org/mailman/listinfo/bbdev
---------------------
Sam Bauers
Automattic, Inc.
sam at automattic.com
http://automattic.com
http://wordpress.com
http://wordpress.org
http://bbpress.org
http://unlettered.org
---------------------
More information about the bbDev
mailing list