Create PHP apps using SQL Server on Windows (ok)

https://www.microsoft.com/en-us/sql-server/developer-get-started/php/windows/step/2.html

Step 2.1 Install the PHP Drivers for SQL Server

Download the Microsoft PHP Drivers for SQL Server from the download page.

Pick the appropriate dll - for example php_pdo_sqlsrv_74_nts.dll for the PDO Driver and php_sqlsrv_74_nts.dll for the SQLSRV driver.

Copy the dll files to the C:\Program Files\iis express\PHP\v7.4\ext folder.

Register the dll files in the php.ini file.Terminal

cd C:\Program^ Files\iis^ express\PHP\v7.4\ext
echo extension=php_sqlsrv_74_nts.dll >> C:\Program^ Files\iis^ express\PHP\v7.4\php.ini
echo extension=php_pdo_sqlsrv_74_nts.dll >> C:\Program^ Files\iis^ express\PHP\v7.4\php.ini Copy

Step 2.2 Create a database for your application

Create the database using sqlcmd.Terminal

sqlcmd -S localhost -U sa -P your_password -Q "CREATE DATABASE SampleDB;" Copy

Step 2.3 Create a PHP app that connects to SQL Server and executes queries

Terminal

mkdir SqlServerSample
cd SqlServerSample Copy

Using your favorite text editor, create a new file called connect.php in the SqlServerSample folder. Paste the code below inside into the new file.PHP

Run your PHP script from the terminal.Terminal

Results

Execute the T-SQL scripts below in the terminal with sqlcmd to create a schema, table, and insert a few rows.Terminal

Using your favorite text editor, create a new file called crud.php in the SqlServerSample folder. Paste the code below inside into the new file. This will insert, update, delete, and read a few rows.PHP

Run your PHP script from the terminal.Terminal

Results

Congratulations! You have created your first PHP app with SQL Server! Check out the next section to learn about how you can make your PHP faster with SQL Server’s Columnstore feature.

Last updated

Was this helpful?