Make WordPress Core

Changeset 1543


Ignore:
Timestamp:
08/20/2004 05:52:49 PM (22 years ago)
Author:
saxmatt
Message:

Some profiling info in $wpdb optionally.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/wp-includes/wp-db.php

    r1475 r1543  
    1010define('ARRAY_A', 'ARRAY_A', false);
    1111define('ARRAY_N', 'ARRAY_N', false);
     12
    1213if (!defined('SAVEQUERIES'))
    1314        define('SAVEQUERIES', false);
    … …  
    1920        var $last_query;
    2021        var $col_info;
     22        var $queries;
    2123
    2224        // Our tables
    … …  
    3941
    4042        function wpdb($dbuser, $dbpassword, $dbname, $dbhost) {
    41                 $this->dbh = @mysql_connect($dbhost,$dbuser,$dbpassword);
     43                $this->dbh = @mysql_connect($dbhost, $dbuser, $dbpassword);
    4244                if (!$this->dbh) {
    4345                        $this->bail("
    … …  
    6062
    6163        function select($db) {
    62                 if (!@mysql_select_db($db,$this->dbh)) {
     64                if (!@mysql_select_db($db, $this->dbh)) {
    6365                        $this->bail("
    6466<h1>Can&#8217;t select database</h1>
    … …  
    135137
    136138                // Perform the query via std mysql_query function..
    137                 $this->result = @mysql_query($query,$this->dbh);
     139                if (SAVEQUERIES)
     140                        $this->timer_start();
     141               
     142                $this->result = @mysql_query($query, $this->dbh);
    138143                ++$this->num_queries;
    139                 if (SAVEQUERIES) {
    140                         $this->savedqueries[] = $query;
    141                 }
     144
     145                if (SAVEQUERIES)
     146                        $this->queries[] = array( $query, $this->timer_stop() );
    142147
    143148                // If there is an error then take note of it..
    … …  
    279284        }
    280285
     286        function timer_start() {
     287                $mtime = microtime();
     288                $mtime = explode(' ', $mtime);
     289                $this->time_start = $mtime[1] + $mtime[0];
     290                return true;
     291        }
     292       
     293        function timer_stop($precision = 3) {
     294                $mtime = microtime();
     295                $mtime = explode(' ', $mtime);
     296                $time_end = $mtime[1] + $mtime[0];
     297                $time_total = $time_end - $this->time_start;
     298                return $timetotal;
     299        }
     300
    281301        function bail($message) { // Just wraps errors in a nice header and footer
    282 echo <<<HEAD
    283 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    284 <html xmlns="http://www.w3.org/1999/xhtml">
    285 <head>
    286         <title>WordPress &rsaquo; Installation</title>
    287         <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    288         <style media="screen" type="text/css">
    289         <!--
    290         html {
    291                 background: #eee;
    292         }
    293         body {
    294                 background: #fff;
    295                 color: #000;
    296                 font-family: Georgia, "Times New Roman", Times, serif;
    297                 margin-left: 25%;
    298                 margin-right: 25%;
    299                 padding: .2em 2em;
    300         }
     302        if ( !$this->show_errors )
     303                return false;
     304        echo <<<HEAD
     305        <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
     306        <html xmlns="http://www.w3.org/1999/xhtml">
     307        <head>
     308                <title>WordPress &rsaquo; Error</title>
     309                <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
     310                <style media="screen" type="text/css">
     311                <!--
     312                html {
     313                        background: #eee;
     314                }
     315                body {
     316                        background: #fff;
     317                        color: #000;
     318                        font-family: Georgia, "Times New Roman", Times, serif;
     319                        margin-left: 25%;
     320                        margin-right: 25%;
     321                        padding: .2em 2em;
     322                }
     323               
     324                h1 {
     325                        color: #006;
     326                        font-size: 18px;
     327                        font-weight: lighter;
     328                }
     329               
     330                h2 {
     331                        font-size: 16px;
     332                }
     333               
     334                p, li, dt {
     335                        line-height: 140%;
     336                        padding-bottom: 2px;
     337                }
    301338       
    302         h1 {
    303                 color: #006;
    304                 font-size: 18px;
    305                 font-weight: lighter;
    306         }
    307        
    308         h2 {
    309                 font-size: 16px;
    310         }
    311        
    312         p, li, dt {
    313                 line-height: 140%;
    314                 padding-bottom: 2px;
    315         }
    316 
    317         ul, ol {
    318                 padding: 5px 5px 5px 20px;
    319         }
    320         #logo {
    321                 margin-bottom: 2em;
    322         }
    323         -->
    324         </style>
    325 </head>
    326 <body>
    327 <h1 id="logo"><img alt="WordPress" src="http://static.wordpress.org/logo.png" /></h1>
     339                ul, ol {
     340                        padding: 5px 5px 5px 20px;
     341                }
     342                #logo {
     343                        margin-bottom: 2em;
     344                }
     345                -->
     346                </style>
     347        </head>
     348        <body>
     349        <h1 id="logo"><img alt="WordPress" src="http://static.wordpress.org/logo.png" /></h1>
    328350HEAD;
    329 echo $message;
    330 echo "</body></html>";
    331 die();
     351        echo $message;
     352        echo "</body></html>";
     353        die();
    332354        }
    333355}
    334356
    335357$wpdb = new wpdb(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST);
    336 
    337358?>
Note: See TracChangeset for help on using the changeset viewer.