Use the php mssql_connect with dblib on SQL Server 2008 (Tested)

Started by fratika, May 26, 2023, 10:51 PM

fratika

How to Use `php_mssql_connect` on SQL Server 2008 with the `dblib` Extension

Part I: Preparing the Environment
1. **Stopping Services** 
  Stop all WebServer services and the SQL Server (Express) service.

2. **Downloading and Installing `ntwdblib.dll`** 
  Download `ntwdblib.dll` version 2000.80.194.0. You can obtain this file by downloading MS SQL Server 2000 SP4 from the Microsoft website. The file can be found in the system directory.

3. **Copying and Replacing the `ntwdblib.dll` File** 
  Replace any other versions of this file in the following locations (directories may vary depending on the web server):
  - Your PHP binaries folder (`webserver\php`)
  - Your Apache binaries folder (`webserver\apache\bin`)
  - `Windows\System32\`

4. **Configuring SQL Server** 
  Ensure that SQL Server is configured to accept TCP connections and Named Pipes through the SQL Server Configuration Manager.

5. **Setting Up Mixed Mode Authentication** 
  Configure SQL Server for Mixed Mode authentication and remember the password you set for the `sa` user.

6. **Starting the SQL Server Service** 
  Restart the SQL Server service.

7. **Editing the `php.ini` File** 
  Set `mssql.secure_connection = On` in your `php.ini` file.

8. **Verifying Access Rights** 
  Ensure that your web server folder has proper access rights (full control for 'everyone').

9. **Starting All Web Server Services** 
  Start all services of your web server.

Part II: Configuring `php.ini` for dblib

1. **Editing Your Web Server's `php.ini` File** 
  Open your web server's `php.ini` file.

2. **Disabling the `php_mssql.dll` Extension** 
  Find the line `extension=php_mssql.dll` and comment it out by adding `;` at the beginning of the line (example: `;extension=php_mssql.dll`).

3. **Copying `php_dblib.dll`** 
  Copy the `php_dblib.dll` file to the `php\ext` folder.

4. **Enabling the `php_dblib.dll` Extension** 
  In the `php.ini` file, add the line `extension=php_dblib.dll` as the last extension row.

5. **Restarting Your Web Server** 
  Restart your web server for the changes to take effect.

Connecting to Your SQL Server Instance

You can connect to your SQL Server instance using the following PHP code:

```php
$dbhandle = mssql_connect('.\SQLEXPRESS','username','password');
$db = mssql_select_db('databasename', $dbhandle);

This guide has been tested on PHP 5.2.9 and SQL Server 2008.
You require the following to view this post content:
  • You must thank this post to see the content.

Fratika is the best :D
  •  

Powered by SMFPacks Ads Manager Mod