Microsoft (SQL Server 2.0) Drivers for PHP!! using SQLSRV
STEPS:
1. First we need to install SQL Server Native Client before installing SQL driver for PHP in your System.
My System Configuration is,
Operating System: Windows 7
System Type: 32-bit Operating System
Install from the http://technet.microsoft.com/en-us/library/cc296170.aspx
— We will get a page titles System Requirements
— We can see a link “Download the X86 package” (If 64-bit OS download X64 package)
— Click the link will download the required file.
— Install it into our system.
2. Download SQLSRV30.EXE OR SQLSRV20.EXE from http://www.microsoft.com/download/en/details.aspx?id=17308
as per our system requirements.
Check php.ini – If
Compiler | MSVC9 (Visual C++ 2008) |
Then download php_sqlsrv_53_ts_vc9.dll and include in php.ini as STEP 5.
3.Run the SQLSRV30.EXE OR SQLSRV20.EXE file will ask path for placing the files. Select the PHP extension Directory.
Ex: D:\wamp\bin\php\php5.3.8\ext
4. Also check in php.ini
extension_dir = “D:/wamp/bin/php/php5.3.8/ext/”
5. Include in php.ini as,
extension=php_sqlsrv_53_ts.dll
OR
extension=php_sqlsrv_53_ts_vc6.dll
OR
extension=php_sqlsrv_53_ts_vc9.dll
See the configuration of your system and enable it in php.ini
6. Restart the wampp Server. If not reflected in phpinfo(), restart the sytem.
PHP Code to Connect
=================
<?php//phpinfo();/*Connect to the local server using Windows Authentication and specifythe AdventureWorks database as the database in use. To connect usingSQL Server Authentication, set values for the “UID” and “PWD”attributes in the $connectionInfo parameter. For example:$connectionInfo = array(“UID” => $uid, “PWD” => $pwd, “Database”=>”AdventureWorks”);*/$serverName = “10.18.1.254\SQL2000”;
$connectionInfo = array( “Database”=>”MCMS”, “UID”=>”sa”, “PWD”=>”Defiance123”); $conn = sqlsrv_connect( $serverName, $connectionInfo); if( $conn ) { //echo “Connection established.\n”; /* Get the product picture for a given product ID. */ $tsql = “SELECT [BlobData] FROM [MCMS].[dbo].[BlobTable] WHERE BlobId = ?”; $params = array(24); /* Execute the query. */ $stmt = sqlsrv_query($conn, $tsql, $params); if( $stmt === false ) { echo “Error in statement execution.</br>”; die( print_r( sqlsrv_errors(), true)); } /* Retrieve the image as a binary stream. */ $getAsType = SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_BINARY); if ( sqlsrv_fetch( $stmt ) ) { $image = sqlsrv_get_field( $stmt, 0, $getAsType); fpassthru($image); } else { echo “Error in retrieving data.</br>”; die(print_r( sqlsrv_errors(), true)); } /* Free the statement and connectin resources. */ sqlsrv_free_stmt( $stmt ); sqlsrv_close( $conn ); } else { echo “Connection could not be established.\n”; die( print_r( sqlsrv_errors(), true)); } ?> |
This driver applies only to IIS or is it possible to load it from apache too???
I have configured with wamp only (PHP, Apache, SQL SERVER)