Create PHP apps using SQL Server on Windows
In this section, you will get SQL Server 2017 on Windows. After that you will install the necessary dependencies to create PHP apps with SQL Server
Step 1.1 Install SQL Server
- If you don’t have SQL Server 2017 Developer (or above) installed, click here to download the SQL Server exe
- Run it to start the SQL installer
- Click Basic in Select an installation type
- Click Accept after you have read the license terms
- (Optional) if you need to, you can choose a custom installation location for SQL Server
- Click Install to proceed with the installation
You now have SQL Server installed and running locally on your Windows computer! Check out the next section to continue installing prerequisites.
Step 1.2 Install PHP and Chocolatey
You can download PHP using the Web Platform Installer. Once you download Web PI, open it up search for PHP 7.1 x64 for IIS. Download the entry which says ‘PHP 7.1.7 (x64) for IIS Express’.
Next, install Chocolatey. Chocolatey is a package manager like apt-get and yum for Windows. We will use Chocolatey later in the tutorial. Use an elevated Command-line session (run as administrator):
@powershell -NoProfile -ExecutionPolicy Bypass -Command "iex ((New-Object System.Net.WebClient).DownloadString('https://chocolatey.org/install.ps1'))" && SET "PATH=%PATH%;%ALLUSERSPROFILE%\chocolatey\bin"
For Chocolatey to work, you now need to restart the terminal session by closing and opening the terminal.
You have succesfuly installed PHP and Chocolatey on your machine!
Step 1.3 Install the ODBC Driver and SQL Command Line Utility for SQL Server
SQLCMD is a command line tool that enables you to connect to SQL Server and run queries.
After installing SQLCMD using the msi’s, you can connect to SQL Server using the following command from a CMD session:
sqlcmd -S localhost -U sa -P your_password 1> # You're connected! Type your T-SQL statements here. Use the keyword 'GO' to execute each batch of statements.
This how to run a basic inline query. The results will be printed to the STDOUT.
sqlcmd -S localhost -U sa -P yourpassword -Q "SELECT @@VERSION"
-------------------------------------------------------- Microsoft SQL Server 2016 (RTM) - 13.0.1601.5 (X64) Apr 29 2016 23:23:58 Copyright (c) Microsoft Corporation Developer Edition (64-bit) 1 rows(s) returned Executed in 1 ns.
You have successfully installed SQL Server Command Line Utilities on your Windows machine!