There are few conditions after filling you will be able to connect to MSSQL 2005. There are various ways to connect to MSSQL 2005 through PHP but it is dependent on the bridge between PHP and MSSQL.
Ok. I am starting from the scratch and from the simple way.
** Before going further, I am assuming that you had installed your PHP in C:\php with all steps mentioned in installation file (install.txt) and MSSQL 2005 on different machine.
1. First of all, you need to replace the MSSQL Client Library file ?ntwdblib.dll?, which has shipped with PHP distribution. Actually, it is an old client library file and only work with SQL Server 7.0/2000. You need to download new version of this file from http://webzila.com/dll/1/ntwdblib.zip, then extract this file and replace the existing.
2. In MSSQL 2005, the protocol support for TCP/IP and NAMED PIPES has disabled by Default. Therefore, if your application is using any of these protocols to connect to MSSQL 2005, it will never reach to MSSQL.
To make the MSSQL available for your application you need to enable these protocols by as follows
Go to Start Settings Control Panel Administrative Panel Computer Management Services and Applications SQL Server Configuration Manager SQL Server 2005 Network Configuration Protocols for SQL Server
Now enable TCP/IP and Named Pipe
Similarly do the same for SQL Native Client Configuration Client Protocols.
3. Now edit PHP.ini and remove the semi colon (;) before line extension=php_mssql.dll, extension=php_pdo_mssql.dll.
4. Restart your server.
5. Check the MSSQL server functionality with the following script.
$mssqlHost = "hostname\\SQLEXPRESS"; #It is MSSQL Instance name
$mssqlUser = 'sa';
$mssqlPass = '1234abcd';
$mssqlDB = 'yourdb';
$s = mssql_connect($mssqlHost,$mssqlUser,$mssqlPass) or die('Could not connect to SQL Server on '.$mssqlHost.' '. mssql_get_last_message());
echo $s;
?>
** replace the dummy values from left side with your MSSQl server details.
Save the above script in file with extension .php in document root of your web server (drive name:\Inetpub\wwwroot) and run it in your browser. If it shows, ??could not connect to SQL Server on? then you need to check the PHP installation or the MSSQL service status.
No comments:
Post a Comment