summaryrefslogtreecommitdiffstats
path: root/wp-includes/wp-db.php
diff options
context:
space:
mode:
Diffstat (limited to 'wp-includes/wp-db.php')
-rw-r--r--wp-includes/wp-db.php87
1 files changed, 60 insertions, 27 deletions
diff --git a/wp-includes/wp-db.php b/wp-includes/wp-db.php
index e1fe61e..06682f2 100644
--- a/wp-includes/wp-db.php
+++ b/wp-includes/wp-db.php
@@ -37,9 +37,13 @@ class wpdb {
var $optiongroup_options;
var $postmeta;
- // ==================================================================
- // DB Constructor - connects to the server and selects a database
-
+ /**
+ * Connects to the database server and selects a database
+ * @param string $dbuser
+ * @param string $dbpassword
+ * @param string $dbname
+ * @param string $dbhost
+ */
function wpdb($dbuser, $dbpassword, $dbname, $dbhost) {
if( defined( "WP_USE_MULTIPLE_DB" ) && CONSTANT( "WP_USE_MULTIPLE_DB" ) == true ) {
@@ -64,9 +68,10 @@ class wpdb {
$this->select($dbname, $this->dbh);
}
- // ==================================================================
- // Select a DB (if another one needs to be selected)
-
+ /**
+ * Selects a database using the current class's $this->dbh
+ * @param string $db name
+ */
function select($db, &$dbh) {
if (!@mysql_select_db($db, $dbh)) {
$this->bail("
@@ -80,9 +85,12 @@ class wpdb {
}
}
- // ====================================================================
- // Format a string correctly for safe insert under all PHP conditions
-
+ /**
+ * Escapes content for insertion into the database, for security
+ *
+ * @param string $string
+ * @return string query safe string
+ */
function escape($string) {
return addslashes( $string ); // Disable rest for now, causing problems
if( !$this->dbh || version_compare( phpversion(), '4.3.0' ) == '-1' )
@@ -259,9 +267,13 @@ class wpdb {
return $return_val;
}
- // ==================================================================
- // Get one variable from the DB - see docs for more detail
-
+ /**
+ * Get one variable from the database
+ * @param string $query (can be null as well, for caching, see codex)
+ * @param int $x = 0 row num to return
+ * @param int $y = 0 col num to return
+ * @return mixed results
+ */
function get_var($query=null, $x = 0, $y = 0) {
$this->func_call = "\$db->get_var(\"$query\",$x,$y)";
if ( $query )
@@ -276,9 +288,13 @@ class wpdb {
return (isset($values[$x]) && $values[$x]!=='') ? $values[$x] : null;
}
- // ==================================================================
- // Get one row from the DB - see docs for more detail
-
+ /**
+ * Get one row from the database
+ * @param string $query
+ * @param string $output ARRAY_A | ARRAY_N | OBJECT
+ * @param int $y row num to return
+ * @return mixed results
+ */
function get_row($query = null, $output = OBJECT, $y = 0) {
$this->func_call = "\$db->get_row(\"$query\",$output,$y)";
if ( $query )
@@ -298,10 +314,12 @@ class wpdb {
}
}
- // ==================================================================
- // Function to get 1 column from the cached result set based in X index
- // se docs for usage and info
-
+ /**
+ * Gets one column from the database
+ * @param string $query (can be null as well, for caching, see codex)
+ * @param int $x col num to return
+ * @return array results
+ */
function get_col($query = null , $x = 0) {
if ( $query )
$this->query($query);
@@ -313,9 +331,12 @@ class wpdb {
return $new_array;
}
- // ==================================================================
- // Return the the query as a result set - see docs for more details
-
+ /**
+ * Return an entire result set from the database
+ * @param string $query (can also be null to pull from the cache)
+ * @param string $output ARRAY_A | ARRAY_N | OBJECT
+ * @return mixed results
+ */
function get_results($query = null, $output = OBJECT) {
$this->func_call = "\$db->get_results(\"$query\", $output)";
@@ -342,11 +363,12 @@ class wpdb {
}
}
-
- // ==================================================================
- // Function to get column meta data info pertaining to the last query
- // see docs for more info and usage
-
+ /**
+ * Grabs column metadata from the last query
+ * @param string $info_type one of name, table, def, max_length, not_null, primary_key, multiple_key, unique_key, numeric, blob, type, unsigned, zerofill
+ * @param int $col_offset 0: col name. 1: which table the col's in. 2: col's max length. 3: if the col is numeric. 4: col's type
+ * @return mixed results
+ */
function get_col_info($info_type = 'name', $col_offset = -1) {
if ( $this->col_info ) {
if ( $col_offset == -1 ) {
@@ -362,6 +384,9 @@ class wpdb {
}
}
+ /**
+ * Starts the timer, for debugging purposes
+ */
function timer_start() {
$mtime = microtime();
$mtime = explode(' ', $mtime);
@@ -369,6 +394,10 @@ class wpdb {
return true;
}
+ /**
+ * Stops the debugging timer
+ * @return int total time spent on the query, in milliseconds
+ */
function timer_stop($precision = 3) {
$mtime = microtime();
$mtime = explode(' ', $mtime);
@@ -377,6 +406,10 @@ class wpdb {
return $time_total;
}
+ /**
+ * Wraps fatal errors in a nice header and footer and dies.
+ * @param string $message
+ */
function bail($message) { // Just wraps errors in a nice header and footer
if ( !$this->show_errors )
return false;