Ticket #2474: wpdb-comments-2.diff
File wpdb-comments-2.diff, 6.1 KB (added by , 19 years ago) |
---|
-
wp-includes/wp-db.php
36 36 var $optiongroup_options; 37 37 var $postmeta; 38 38 39 // ================================================================== 40 // DB Constructor - connects to the server and selects a database 41 39 /** 40 * Connects to the database server and selects a database 41 * @param string $dbuser 42 * @param string $dbpassword 43 * @param string $dbname 44 * @param string $dbhost 45 */ 42 46 function wpdb($dbuser, $dbpassword, $dbname, $dbhost) { 43 47 $this->dbh = @mysql_connect($dbhost, $dbuser, $dbpassword); 44 48 if (!$this->dbh) { … … 57 61 $this->select($dbname); 58 62 } 59 63 60 // ================================================================== 61 // Select a DB (if another one needs to be selected) 62 64 /** 65 * Selects a database using the current class's $this->dbh 66 * @param string $db name 67 */ 63 68 function select($db) { 64 69 if (!@mysql_select_db($db, $this->dbh)) { 65 70 $this->bail(" … … 73 78 } 74 79 } 75 80 76 // ==================================================================== 77 // Format a string correctly for safe insert under all PHP conditions 78 81 /** 82 * Escapes content for insertion into the database, for security 83 * 84 * @param string $string 85 * @return string query safe string 86 */ 79 87 function escape($string) { 80 88 return addslashes( $string ); // Disable rest for now, causing problems 81 89 if( !$this->dbh || version_compare( phpversion(), '4.3.0' ) == '-1' ) … … 105 113 } 106 114 } 107 115 108 / / ==================================================================109 // Turn error handling on or off..110 116 /** 117 * Turn error reporting for SQL errors on 118 */ 111 119 function show_errors() { 112 120 $this->show_errors = true; 113 121 } 114 122 123 /** 124 * Turn error reporting for SQL errors off 125 */ 115 126 function hide_errors() { 116 127 $this->show_errors = false; 117 128 } 118 129 119 / / ==================================================================120 // Kill cached queryresults121 130 /** 131 * Flush the internal wpdb cache which stores the last query's results 132 */ 122 133 function flush() { 123 134 $this->last_result = null; 124 135 $this->col_info = null; 125 136 $this->last_query = null; 126 137 } 127 138 128 // ================================================================== 129 // Basic Query - see docs for more detail 130 139 /** 140 * Simply run an SQL query 141 * @param string $query 142 * @return mixed number of rows affected rows 143 */ 131 144 function query($query) { 132 145 // initialise return 133 146 $return_val = 0; … … 145 158 146 159 $this->result = @mysql_query($query, $this->dbh); 147 160 ++$this->num_queries; 148 161 149 162 if (SAVEQUERIES) 150 163 $this->queries[] = array( $query, $this->timer_stop() ); 151 164 … … 187 200 return $return_val; 188 201 } 189 202 190 // ================================================================== 191 // Get one variable from the DB - see docs for more detail 192 203 /** 204 * Get one variable from the database 205 * @param string $query (can be null as well, for caching, see codex) 206 * @param int $x = 0 optional x offset 207 * @param int $y = 0 optional y offset 208 * @return mixed results 209 */ 193 210 function get_var($query=null, $x = 0, $y = 0) { 194 211 $this->func_call = "\$db->get_var(\"$query\",$x,$y)"; 195 212 if ( $query ) … … 204 221 return (isset($values[$x]) && $values[$x]!=='') ? $values[$x] : null; 205 222 } 206 223 207 // ================================================================== 208 // Get one row from the DB - see docs for more detail 209 224 /** 225 * Get one row from the database 226 * @param string $query 227 * @param string $output ARRAY_A | ARRAY_N | OBJECt 228 * @param int $y y-axis to return the results from 229 * @return mixed results 230 */ 210 231 function get_row($query = null, $output = OBJECT, $y = 0) { 211 232 $this->func_call = "\$db->get_row(\"$query\",$output,$y)"; 212 233 if ( $query ) … … 223 244 } 224 245 } 225 246 226 // ================================================================== 227 // Function to get 1 column from the cached result set based in X index 228 // se docs for usage and info 229 247 /** 248 * Gets one column from the database 249 * @param string $query (can be null as well, for caching, see codex) 250 * @param int $x x-axis of the column you want returned 251 * @return array results 252 */ 230 253 function get_col($query = null , $x = 0) { 231 254 if ( $query ) 232 255 $this->query($query); … … 238 261 return $new_array; 239 262 } 240 263 241 // ================================================================== 242 // Return the the query as a result set - see docs for more details 243 264 /** 265 * Return an entire result set from the database 266 * @param string $query (can also be null to pull from the cache) 267 * @param string $output ARRAY_A | ARRAY_N | OBJECT 268 * @return mixed results 269 */ 244 270 function get_results($query = null, $output = OBJECT) { 245 271 $this->func_call = "\$db->get_results(\"$query\", $output)"; 246 272 … … 267 293 } 268 294 } 269 295 270 271 // ================================================================== 272 // Function to get column meta data info pertaining to the last query 273 // see docs for more info and usage 274 296 /** 297 * Grabs column metadata from the last query 298 * @param string $info_type one of name, table, def, max_length, not_null, primary_key, multiple_key, unique_key, numeric, blob, type, unsigned, zerofill 299 * @param unknown_type $col_offset 300 * @return mixed results 301 */ 275 302 function get_col_info($info_type = 'name', $col_offset = -1) { 276 303 if ( $this->col_info ) { 277 304 if ( $col_offset == -1 ) { … … 287 314 } 288 315 } 289 316 317 /** 318 * Starts the timer, for debugging purposes 319 */ 290 320 function timer_start() { 291 321 $mtime = microtime(); 292 322 $mtime = explode(' ', $mtime); … … 294 324 return true; 295 325 } 296 326 297 function timer_stop($precision = 3) { 327 /** 328 * Stops the debugging timer 329 * @return int total time spent on the query 330 */ 331 function timer_stop() { 298 332 $mtime = microtime(); 299 333 $mtime = explode(' ', $mtime); 300 334 $time_end = $mtime[1] + $mtime[0]; … … 302 336 return $time_total; 303 337 } 304 338 339 /** 340 * Wraps fatal errors in a nice header and footer and die. 341 * @param string $message 342 */ 305 343 function bail($message) { // Just wraps errors in a nice header and footer 306 344 if ( !$this->show_errors ) 307 345 return false;