So I have Microsoft SQL Server 2008 R2 installed and an instance set up with a database an user setup on that database with a password. I have installed PHP, and IIS and got PH working from the WWWROOT folder, but when tryng to connect to my database it is not just not working. I have spent two days straight on this, and pulling my hair out. I was able to connect to the database using ColdFusion and its web server, PHP was meant to be easier! Here is the code i am using to connect to my database:

mysql_connect("MYINSTANCE", "MYUSER", "MYPASSWORD") or die(mysql_error());
echo "Connected to MySQL<br />";
mysql_select_db("test") or die(mysql_error());
echo "Connected to Database";

Obviously I have omitted my server, user and password from the above code. I have installed the drivers from MS and installed into the PHP EXT folder, still no luck, I will appreciate any help from you guys!


5 Years
Discussion Span
Last Post by Biiim

MySQL is not the same as MSSQL. You should not be using the mysql* functions to connect to a microsoft sql server.You want to be using the SQL Server driver (http://msdn.microsoft.com/en-us/sqlserver/ff657782.aspx)

Hi there many thanks for your reply. My mistake, i am using Microsoft SQL server 2008 R2 and not MySQL, I always get confused! ARRGH! The driver you pointed out is in fact the one i downloaded and installed to my PHP/ext directory, I don't know if there was more configuration to do after this, as the tutorial i was following didn't say.



These might be of help:

Wow that actually helped a lot, I eventually got it to connect! YES!!!

But bit of an anti climax as I was excited to be able to insert into tables, but I cannot get this to work, have you any ideas? I am using this code:

$serverName = "myinstance";
$connectionInfo = array("UID" => "myuser", "PWD" => "mypassword", "Database"=>"mydatabase");
$conn = sqlsrv_connect( $serverName, $connectionInfo);

if( $conn === false ) // note the format of ‘equals’
     echo "Could not connect.\n";
     die( print_r( sqlsrv_errors(), true));

mysql_select_db("TutorialTwo", $con);

VALUES ('60', 'ADMIN', DUNDEE')");

I get no errors, but when I refresh the table in ms sql there is no new addition, I wonder what i am doing wrong??

Thanks for all your help!!!!

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.