I can connect to SQL server from a PHP website using the following code:
<?php
/*
* Follow me on Twitter: @HertogJanR
* Please donate: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=4EFPSXA623NZA
*/
$connectionInfo = array( "UID" => "wordpress", "PWD" => "xxxxxxx", "Database" => "wordpress" );
$link = sqlsrv_connect( ".", $connectionInfo );
if( $link ) {
echo "Connection established.<br />";
} else{
echo "Connection could not be established.<br />";
die( print_r( sqlsrv_errors(), true ) );
}
$sql = "SELECT table_name FROM information_schema.tables";
$stmt = sqlsrv_query( $link, $sql );
while( $row = sqlsrv_fetch_array( $stmt, SQLSRV_FETCH_ASSOC ) ) {
echo $row['table_name']."<br />";
}
if( $stmt === false ) {
die( print_r( sqlsrv_errors(), true));
}
?>
However , i can't get connected using these credentials in the wp-config.php
// ** MySQL settings - You can get this info from your web host ** //
/** The name of the database for WordPress */
define('DB_NAME', 'wordpress');
/** MySQL database username */
define('DB_USER', 'wordpress');
/** MySQL database password */
define('DB_PASSWORD', 'xxxxx');
/** MySQL hostname */
define('DB_HOST', '.'); /* localhost doesn't work either */
The error is: Warning: mysqli_real_connect(): (HY000/2002): Unknown errror while connecting in C:\wordpress\wp-includes\wp-db.php on line 1531
When i change it to localhost the error is different: Warning: mysqli_real_connect(): (HY000/2002): No connection could be made because the target machine actively refused it. in C:\wordpress\wp-includes\wp-db.php on line 1531
Any ideas? The wp-config.php looks like it has variables setup to connect to MySQL How do i tell it to use SQL Server?