Some profiling info in $wpdb optionally.

git-svn-id: http://svn.automattic.com/wordpress/trunk@1543 1a063a9b-81f0-0310-95a4-ce76da25c4cd
This commit is contained in:
saxmatt 2004-08-20 17:52:49 +00:00
parent 3c6bc4ae08
commit 38545517b1
1 changed files with 74 additions and 53 deletions

View File

@ -9,6 +9,7 @@ define('EZSQL_VERSION', 'WP1.25');
define('OBJECT', 'OBJECT', true); define('OBJECT', 'OBJECT', true);
define('ARRAY_A', 'ARRAY_A', false); define('ARRAY_A', 'ARRAY_A', false);
define('ARRAY_N', 'ARRAY_N', false); define('ARRAY_N', 'ARRAY_N', false);
if (!defined('SAVEQUERIES')) if (!defined('SAVEQUERIES'))
define('SAVEQUERIES', false); define('SAVEQUERIES', false);
@ -18,6 +19,7 @@ class wpdb {
var $num_queries = 0; var $num_queries = 0;
var $last_query; var $last_query;
var $col_info; var $col_info;
var $queries;
// Our tables // Our tables
var $posts; var $posts;
@ -38,7 +40,7 @@ class wpdb {
// DB Constructor - connects to the server and selects a database // DB Constructor - connects to the server and selects a database
function wpdb($dbuser, $dbpassword, $dbname, $dbhost) { function wpdb($dbuser, $dbpassword, $dbname, $dbhost) {
$this->dbh = @mysql_connect($dbhost,$dbuser,$dbpassword); $this->dbh = @mysql_connect($dbhost, $dbuser, $dbpassword);
if (!$this->dbh) { if (!$this->dbh) {
$this->bail(" $this->bail("
<h1>Error establishing a database connection</h1> <h1>Error establishing a database connection</h1>
@ -59,7 +61,7 @@ class wpdb {
// Select a DB (if another one needs to be selected) // Select a DB (if another one needs to be selected)
function select($db) { function select($db) {
if (!@mysql_select_db($db,$this->dbh)) { if (!@mysql_select_db($db, $this->dbh)) {
$this->bail(" $this->bail("
<h1>Can&#8217;t select database</h1> <h1>Can&#8217;t select database</h1>
<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>$db</code> database.</p> <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>$db</code> database.</p>
@ -134,11 +136,14 @@ class wpdb {
$this->last_query = $query; $this->last_query = $query;
// Perform the query via std mysql_query function.. // 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; ++$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 there is an error then take note of it..
if ( mysql_error() ) { if ( mysql_error() ) {
@ -278,60 +283,76 @@ class wpdb {
} }
} }
function bail($message) { // Just wraps errors in a nice header and footer function timer_start() {
echo <<<HEAD $mtime = microtime();
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> $mtime = explode(' ', $mtime);
<html xmlns="http://www.w3.org/1999/xhtml"> $this->time_start = $mtime[1] + $mtime[0];
<head> return true;
<title>WordPress &rsaquo; Installation</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<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 { function timer_stop($precision = 3) {
color: #006; $mtime = microtime();
font-size: 18px; $mtime = explode(' ', $mtime);
font-weight: lighter; $time_end = $mtime[1] + $mtime[0];
} $time_total = $time_end - $this->time_start;
return $timetotal;
h2 {
font-size: 16px;
}
p, li, dt {
line-height: 140%;
padding-bottom: 2px;
} }
ul, ol { function bail($message) { // Just wraps errors in a nice header and footer
padding: 5px 5px 5px 20px; if ( !$this->show_errors )
} return false;
#logo { echo <<<HEAD
margin-bottom: 2em; <!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>
</style> <title>WordPress &rsaquo; Error</title>
</head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<body> <style media="screen" type="text/css">
<h1 id="logo"><img alt="WordPress" src="http://static.wordpress.org/logo.png" /></h1> <!--
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="WordPress" src="http://static.wordpress.org/logo.png" /></h1>
HEAD; HEAD;
echo $message; echo $message;
echo "</body></html>"; echo "</body></html>";
die(); die();
} }
} }
$wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST); $wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
?> ?>