Example MS SQL Server Setup
We were able to set up MS SQL Server 2005 Express (free download) and connect to it via PHP by the following steps. There are several versions of MS SQL Server, so additional configuration may be required for other versions.
- Install MS SQL Server 2005 Express.
- Set up a database and table.
- Set up a SQL user.
- Enable Mixed Authentication.
- Add permissions on the database for the created user.
- Add permissions on the table for the created user.
- Access the Server according to the steps outlined below.
Connecting to a MS SQL Server database with PHP
Connecting to a MS SQL Server database with PHP is very similar to connecting to a MySQL database. The following example demonstrates how to connect to a MS SQL database from PHP. Note that the function names contain mssql, not mysql.
$host ="xxx.xxx.xxx.xxx"; $username ="username"; $password ="password"; $database ="database"; mssql_connect($host, $username, $password); mssql_select_db($database); ?>