/** * Connects to the database server and selects a database * * PHP5 style constructor for compatibility with PHP5. Does * the actual setting up of the class properties and connection * to the database. * * @link http://core.trac.wordpress.org/ticket/3354 * @since 2.0.8 * * @param string $dbuser MySQL database user * @param string $dbpassword MySQL database password * @param string $dbname MySQL database name * @param string $dbhost MySQL database host */ function __construct($dbuser, $dbpassword, $dbname, $dbhost) { if (!extension_loaded('mssql')) { $this->bail(' <h1>Extension Not Loaded</h1> <p>The sqlsrv PHP extension is not loaded properly or available for PHP to use.</p> <ul> <li>Check your phpinfo</li> <li>Make sure it is loaded in your php ini file</li> <li>Turn on display_errors and display_startup_errors so you can detect issues with loading the module.</li> </ul>'); return; } parent::__construct($dbuser, $dbpassword, $dbname, $dbhost); }
/** * Connects to the database server and selects a database * * PHP5 style constructor for compatibility with PHP5. Does * the actual setting up of the class properties and connection * to the database. * * @link http://core.trac.wordpress.org/ticket/3354 * @since 2.0.8 * * @param string $dbuser MySQL database user * @param string $dbpassword MySQL database password * @param string $dbname MySQL database name * @param string $dbhost MySQL database host */ function __construct($dbuser, $dbpassword, $dbname, $dbhost) { register_shutdown_function(array($this, '__destruct')); if (WP_DEBUG) { $this->show_errors(); } if (is_multisite()) { $this->charset = 'utf8'; if (defined('DB_COLLATE') && DB_COLLATE) { $this->collate = DB_COLLATE; } else { $this->collate = 'utf8_general_ci'; } } elseif (defined('DB_COLLATE')) { $this->collate = DB_COLLATE; } if (defined('DB_CHARSET')) { $this->charset = DB_CHARSET; } parent::__construct(); $this->db_type = DB_TYPE; $this->dbuser = $dbuser; // Make sure the version is the same for your ntwdblib.dll. // The TDS library and the ntwdblib.dll can't be speaking two different protocols. putenv("TDSVER=70"); // Set text limit sizes to max BEFORE connection is made ini_set('mssql.textlimit', 2147483647); ini_set('mssql.textsize', 2147483647); if (get_magic_quotes_gpc()) { $dbhost = trim(str_replace("\\\\", "\\", $dbhost)); } $this->dbh = mssql_connect($dbhost, $dbuser, $dbpassword); mssql_min_error_severity(0); mssql_min_message_severity(17); if (!$this->dbh) { $this->bail(sprintf("\n<h1>Error establishing a database connection</h1>\n<p>This either means that the username and password information in your <code>wp-config.php</code> file is incorrect or we can't contact the database server at <code>%s</code>. This could mean your host's database server is down.</p>\n<ul>\n <li>Are you sure you have the correct username and password?</li>\n <li>Are you sure that you have typed the correct hostname?</li>\n <li>Are you sure that the database server is running?</li>\n</ul>\n<p>If you're unsure what these terms mean you should probably contact your host. If you still need help you can always visit the <a href='http://wordpress.org/support/'>WordPress Support Forums</a>.</p>\n", $dbhost), 'db_connect_fail'); if (defined('WP_SETUP_CONFIG')) { return; } die; } $this->ready = true; @mssql_query('SET TEXTSIZE 2147483647'); /* if ( $this->has_cap( 'collation' ) && !empty( $this->charset ) ) { if ( function_exists( 'mysql_set_charset' ) ) { mysql_set_charset( $this->charset, $this->dbh ); $this->real_escape = true; } else { $query = $this->prepare( 'SET NAMES %s', $this->charset ); if ( ! empty( $this->collate ) ) $query .= $this->prepare( ' COLLATE %s', $this->collate ); $this->query( $query ); } } */ $this->select($dbname, $this->dbh); }
/** * Connects to the database server and selects a database * * PHP5 style constructor for compatibility with PHP5. Does * the actual setting up of the class properties and connection * to the database. * * @link http://core.trac.wordpress.org/ticket/3354 * @since 2.0.8 * * @param string $dbuser MySQL database user * @param string $dbpassword MySQL database password * @param string $dbname MySQL database name * @param string $dbhost MySQL database host */ function __construct($dbuser, $dbpassword, $dbname, $dbhost, $pdo_type) { $this->pdo_type = $pdo_type; if (!extension_loaded('pdo')) { $this->bail(' <h1>Extension Not Loaded</h1> <p>The pdo PHP extension is not loaded properly or available for PHP to use.</p> <ul> <li>Check your phpinfo</li> <li>Make sure it is loaded in your php ini file</li> <li>Turn on display_errors and display_startup_errors so you can detect issues with loading the module.</li> </ul>'); return; } if (!in_array($this->pdo_type, pdo_drivers())) { $this->bail(' <h1>PDO Driver Not Loaded</h1> <p>The pdo PHP driver extension ' . $this->pdo_type . ' is not loaded properly or available for PHP to use.</p> <ul> <li>Check your phpinfo</li> <li>Make sure it is loaded in your php ini file</li> <li>Turn on display_errors and display_startup_errors so you can detect issues with loading the module.</li> </ul>'); return; } parent::__construct($dbuser, $dbpassword, $dbname, $dbhost); }
/** * Retrieve one variable from the database. * * Executes a SQL query and returns the value from the SQL result. * If the SQL result contains more than one column and/or more than one row, this function returns the value in the column and row specified. * If $query is null, this function returns the value in the specified column and row from the previous SQL result. * * @since 0.71 * * @param string|null $query Optional. SQL query. Defaults to null, use the result from the previous query. * @param int $x Optional. Column of value to return. Indexed from 0. * @param int $y Optional. Row of value to return. Indexed from 0. * @return string|null Database query result (as string), or null on failure */ public function get_var($query = null, $x = 0, $y = 0) { $this->func_call = "\$db->get_var(\"{$query}\", {$x}, {$y})"; if ($this->check_current_query && $this->check_safe_collation($query)) { $this->check_current_query = false; } if ($query && $x == 0 && $y == 0) { $result = sqlsrv_query($this->dbh, $query); // If there is an error, first attempt to translate $errors = sqlsrv_errors(); if (!empty($errors) && is_array($errors)) { switch ($errors[0]['code']) { case 102: case 145: case 156: case 195: case 207: case 241: case 261: case 321: case 1018: case 8120: case 8127: if (getenv('ProjectNamiLogTranslate')) { $begintransmsg = date("Y-m-d H:i:s") . " -- Begin translation attempt: {$query} \n"; error_log($begintransmsg, 3, 'D:\\home\\LogFiles\\translate.log'); } $sqltranslate = new SQL_Translations(DB_USER, DB_PASSWORD, DB_NAME, DB_HOST); $query = $sqltranslate->translate($query); if (getenv('ProjectNamiLogTranslate')) { $endtransmsg = date("Y-m-d H:i:s") . " -- Translation result: {$query} \n"; error_log($endtransmsg, 3, 'D:\\home\\LogFiles\\translate.log'); } $result = sqlsrv_query($this->dbh, $query); } } if (false === $result) { return null; } $row = sqlsrv_fetch_array($result); return $row[0]; } if ($query) { $this->query($query); } // Extract var out of cached results based x,y vals if (!empty($this->last_result[$y])) { if (is_object($this->last_result[$y])) { $values = array_values(get_object_vars($this->last_result[$y])); } else { $values = array_values($this->last_result[$y]); } } // If there is a value return it else return null return isset($values[$x]) && $values[$x] !== '' ? $values[$x] : null; }