Can PHP work with a MS SQL database Can PHP work with a MS SQL database php php

Can PHP work with a MS SQL database


Yes, you can. It depends on which version of PHP you're using, but if you're using PHP5+ you can use Microsoft's SQL Server Driver for PHP. Make sure you use version 2, which gives you the PDO functionality as well as the procedural style.

You can also use the PDO ODBC driver to access a SQL Server instance, but that approach is more buggy and I don't recommend it.

Finally you can use the PHP MSSQL library but that's even worse. Go with Microsoft's own solution if you can.

Edit: Oh, and there's also the DBLIB MSSQL PDO driver - stay away from that one too!


Yes. As long as you have the php_mssql extension on your server, you can use the following common functions:

// Connect to mssql server$handle = mssql_connect($host, $user, $pass) or die("Cannot connect to server");// Select a database$db = mssql_select_db($dn_name, $handle) or die("Cannot select database"); // Execute a query$query = "SELECT * FROM users WHERE lname = 'Smith'";$result = mssql_query($query);// Iterate over results<br />while($row = mssql_fetch_array($result)) {    echo $row["id"];}

Note: From PHP 5.3 this extension is not included (and probably not maintained). You can download and add it manually, or better use Microsoft drivers.


yes you can connect to MsSQL . If you are using wamp then switch on the php extension php_mssql if not then use the php.ini file and modify it