From 38545517b116372b1a62883050721006977846e9 Mon Sep 17 00:00:00 2001 From: saxmatt Date: Fri, 20 Aug 2004 17:52:49 +0000 Subject: [PATCH] Some profiling info in $wpdb optionally. git-svn-id: http://svn.automattic.com/wordpress/trunk@1543 1a063a9b-81f0-0310-95a4-ce76da25c4cd --- wp-includes/wp-db.php | 127 ++++++++++++++++++++++++------------------ 1 file changed, 74 insertions(+), 53 deletions(-) diff --git a/wp-includes/wp-db.php b/wp-includes/wp-db.php index 29e6f8cbd..1839fb139 100644 --- a/wp-includes/wp-db.php +++ b/wp-includes/wp-db.php @@ -9,6 +9,7 @@ define('EZSQL_VERSION', 'WP1.25'); define('OBJECT', 'OBJECT', true); define('ARRAY_A', 'ARRAY_A', false); define('ARRAY_N', 'ARRAY_N', false); + if (!defined('SAVEQUERIES')) define('SAVEQUERIES', false); @@ -18,6 +19,7 @@ class wpdb { var $num_queries = 0; var $last_query; var $col_info; + var $queries; // Our tables var $posts; @@ -38,7 +40,7 @@ class wpdb { // DB Constructor - connects to the server and selects a database function wpdb($dbuser, $dbpassword, $dbname, $dbhost) { - $this->dbh = @mysql_connect($dbhost,$dbuser,$dbpassword); + $this->dbh = @mysql_connect($dbhost, $dbuser, $dbpassword); if (!$this->dbh) { $this->bail("

Error establishing a database connection

@@ -59,7 +61,7 @@ class wpdb { // Select a DB (if another one needs to be selected) function select($db) { - if (!@mysql_select_db($db,$this->dbh)) { + if (!@mysql_select_db($db, $this->dbh)) { $this->bail("

Can’t select database

We were able to connect to the database server (which means your username and password is okay) but not able to select the $db database.

@@ -134,11 +136,14 @@ class wpdb { $this->last_query = $query; // Perform the query via std mysql_query function.. - $this->result = @mysql_query($query,$this->dbh); + if (SAVEQUERIES) + $this->timer_start(); + + $this->result = @mysql_query($query, $this->dbh); ++$this->num_queries; - if (SAVEQUERIES) { - $this->savedqueries[] = $query; - } + + if (SAVEQUERIES) + $this->queries[] = array( $query, $this->timer_stop() ); // If there is an error then take note of it.. if ( mysql_error() ) { @@ -278,60 +283,76 @@ class wpdb { } } - function bail($message) { // Just wraps errors in a nice header and footer -echo << - - - WordPress › Installation - - - - -

WordPress

+ function bail($message) { // Just wraps errors in a nice header and footer + if ( !$this->show_errors ) + return false; + echo << + + + WordPress › Error + + + + +

WordPress

HEAD; -echo $message; -echo ""; -die(); + echo $message; + echo ""; + die(); } } $wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST); - ?> \ No newline at end of file