]> scripts.mit.edu Git - autoinstalls/wordpress.git/blobdiff - wp-includes/wp-db.php
Wordpress 2.0.11
[autoinstalls/wordpress.git] / wp-includes / wp-db.php
index 97238c39792b3f360ca85487e471ac0685d6169c..790ddcfdee26c13734b01c655e7cd2b05860d424 100644 (file)
@@ -40,6 +40,12 @@ class wpdb {
        //      DB Constructor - connects to the server and selects a database
 
        function wpdb($dbuser, $dbpassword, $dbname, $dbhost) {
+               return $this->__construct($dbuser, $dbpassword, $dbname, $dbhost);
+       }
+       
+       function __construct($dbuser, $dbpassword, $dbname, $dbhost) {
+               register_shutdown_function(array(&$this, "__destruct"));
+
                $this->dbh = @mysql_connect($dbhost, $dbuser, $dbpassword);
                if (!$this->dbh) {
                        $this->bail("
@@ -57,6 +63,10 @@ class wpdb {
                $this->select($dbname);
        }
 
+       function __destruct() {
+               return true;            
+       }
+
        // ==================================================================
        //      Select a DB (if another one needs to be selected)
 
@@ -93,12 +103,14 @@ class wpdb {
                $EZSQL_ERROR[] = 
                array ('query' => $this->last_query, 'error_str' => $str);
 
+               $str = htmlspecialchars($str, ENT_QUOTES);
+               $query = htmlspecialchars($this->last_query, ENT_QUOTES);
                // Is error output turned on or not..
                if ( $this->show_errors ) {
                        // If there is an error then take note of it
                        print "<div id='error'>
                        <p class='wpdberror'><strong>WordPress database error:</strong> [$str]<br />
-                       <code>$this->last_query</code></p>
+                       <code>$query</code></p>
                        </div>";
                } else {
                        return false;   
@@ -120,7 +132,7 @@ class wpdb {
        //      Kill cached query results
 
        function flush() {
-               $this->last_result = null;
+               $this->last_result = array();
                $this->col_info = null;
                $this->last_query = null;
        }
@@ -129,6 +141,11 @@ class wpdb {
        //      Basic Query     - see docs for more detail
 
        function query($query) {
+               // filter the query, if filters are available
+               // NOTE: some queries are made before the plugins have been loaded, and thus cannot be filtered with this method
+               if ( function_exists('apply_filters') )
+                       $query = apply_filters('query', $query);
+
                // initialise return
                $return_val = 0;
                $this->flush();