14 October 2008

How to Connect to SQL Server 2000 with PHP Using php_mssql.dll

PHP is powerful tool for build up your web applications because PHP is an easy to learn. SQL server is a Microsoft’s robust database product, which can handle terabytes of your data.

In web database application, usually some web programmers use PHP to connect to MySQL database. But in the other side, there are many web programmers looking for information how to connecting PHP to SQL Server 2000.

Well, this time I’ll share about how to connecting PHP to SQL Server using php_mssql.dll.

I use Windows Vista 32 bit for the OS, SQL Server 2000, PHP version 5.2.3 and AppServ version 2.5.9 for Windows for Web Server.

The php_mssql.dll file is already exists in extension or ext directory of your PHP installation folder. Before you can use the php_mssql.dll, you must make a modification in php.ini file, which is placed in C:\Windows directory, or If you’re using php before version 5, the php.ini file is in php installation folder.



  • Open the php.ini file using Notepad or WordPad.
  • In Notepad window, press Ctrl + F to find this word: “extension=php_mssql.dll”.
  • Delete the semicolon mark (;).
  • Save the php.ini file.
  • Restart the web server using "net stop apache" and then "net start apache" from your computer DOS promp. Or maybe you need to restart your computer.
Now, let’s test the php_mssql.dll, it is already run perfectly or not. You can check by using phpinfo() function. Type this address in your browser: http://localhost/phpinfo.php



In the PHP configuration information, you should see something like this:

Now, your Apache web server is ready to make a connection between PHP and SQL Server 2000 using php_mssql.dll.

Create connect.php file. This file is example how to connect PHP to SQL Server 2000.

$host = "rafa-comp"; //set the host with server name or ip address
$user = "sa"; //set the user id
$password =""; //set the user password (blank password is not recomended)
$database = "Northwind"; //set the database to use
if (mssql_connect($host, $user, $password)) {
echo 'Connection to SQL Server success, ';
if (mssql_select_db($database)) {
echo "$database database is selected"; }
else {
echo 'database not found';}
}
else {
echo 'Sorry my bro, connection to SQL Server failed';
}


Save the connect.php file in your web root directory. Run it through your browser. Your browser return should look like this:


OK, I hope this onformation is usefull. Have a nice day :-)




1 comment:

isikegemen said...

https://programmingtutorialsscript.blogspot.com/?zx=c1226e9b4dfb4b8f