PHP‎ > ‎

Use PHP to create an ADO recordset with SQL Server

This is an example on how to connect to MSSQL server with ADODB and PHP.

NOTE: your php.ini must contain this line:


To connect do the following

$myServer = "localhost";
$myUser = "MyUser";
$myPass = "MyPass"; 
$myDB= "MyDatabase"; 
$conn = new COM ("ADODB.Connection")
or die("Cannot start ADO");
$connStr = "PROVIDER=SQLOLEDB;SERVER=".$myServer.";UID=".$myUser.";PWD=".$myPass.";DATABASE=".$myDB; 

$select = "SELECT * FROM MyDatabaseTable";
$rs = $conn->execute($select);
      echo $rs->Fields['MyField']->value."<br>";
$rs = null;

$conn = null; 

NOTE:   if you want to do an insert statement, you open the connection in the same way as shown above, and then you do this:

$strSQL = "insert into icb_weblogins (userid) values ('')";