advertisement
How To Connact laravel to sql server
Here are the steps for configuring SQLSRV extension for WAMP server based on whether Thread Safety is enabled or not:
Step 1: Check if Thread Safety is Enabled in PHP
- Create a PHP Info File:
- Create a new file (e.g., phpinfo.php) in your web root (e.g., www folder in WAMP).
- Add the following code in that file:
- Open this file in your browser (e.g., http://localhost/phpinfo.php).
- Look for Thread Safety in the output.
- If it shows enabled, that means Thread Safety is enabled.
- If it shows disabled, that means Thread Safety is disabled.
Step 2: Download the Correct SQLSRV Files
- Based on the Thread Safety result:
- If Thread Safety is enabled, you will need:
- php_pdo_sqlsrv_82_ts_x64.dll
- php_sqlsrv_82_ts_x64.dll
- If Thread Safety is disabled, you will need:
- php_pdo_sqlsrv_82_nts_x64.dll
- php_sqlsrv_82_nts_x64.dll
- Download Link: You can download these files from the official Microsoft PHP Driver for SQL Server GitHub repository:
Step 3: Place the DLL Files in the PHP Extension Directory
- After downloading the correct DLL files based on your Thread Safety setting, place them in the ext directory of your PHP installation. This is typically located in:
- C:\wamp\bin\php\php[version]\ext\
Step 4: Edit the php.ini File
- Open the php.ini file for your PHP version in WAMP:
- This file is located in C:\wamp\bin\php\php[version]\php.ini.
- Add the following lines to the file to enable the SQLSRV extensions:
- For Thread Safety enabled (_ts files)
- For Thread Safety disabled (_nts files):
Save the php.ini file after editing.
Step 5: Configure .env File for Database Connection
- Open your .env file in the root of your Laravel or PHP project.
- Add the following lines to configure your database connection
Step 6: Firewall and SQL Server Configuration
- Firewall Configuration:
- Open Windows Firewall.
- Go to Advanced Settings.
- Create a new Inbound Rule to allow TCP traffic on port 1433 (default SQL Server port).
- This allows the WAMP server to communicate with SQL Server.
2. Enable TCP/IP in SQL Server Configuration Manager:
- Open SQL Server Configuration Manager.
- Navigate to SQL Server Network Configuration > Protocols for [Instance Name].
- Right-click TCP/IP, and select Enable.
- Under the IP Addresses tab, make sure IPAll section has TCP Port 1433 set.
- Restart your SQL Server service after making these changes.
Step 7: Restart WAMP Server
- After completing all the steps, restart the WAMP server to apply the changes.
advertisement
Conversation
Your input fuels progress! Share your tips or experiences on prioritizing mental wellness at work. Let's inspire change together!
Join the discussion and share your insights now!
Comments 1
Zia
2 weeks ago
Informative Content! ❤