“Good ideas are a dime a dozen, but implementation is priceless!”

Before using PHP5.3, I never had to worry about MSSQL support. PHP included a dll file to use with MSSQL Server 2000 and up. This is no longer true if you decide to upgrade to PHP5.3.x. For months I looked for ways to connect to our MSSQL Server using PHP5.3.x. I finally found the driver and it works. It’s called SQLSRV and you can download it from http://sqlsrvphp.codeplex.com. It’s easy to install, just read the CHM file.

  • Run the exe to unpack it
  • Rename the folder to Microsoft SQL Server Driver for PHP (optional)
  • Move this to your %Program Files% directory (optional)
  • Inside that directory you will find several dll files. It supports both NTS (Non Thread Safe) and TS (Thread Safe). You also need to choose between VC6 or VC9 compiler. This will determine which file will be used.
  • Copy that file to %Installation Directory%\PHP\ext\ (assuming you are using the ext directory for your extensions.
  • Edit your php.ini. In the extensions section add the following extension=php_sqlsrv_53_ts_vc6.dll – or whatever file you copied to your ext directory.
  • Restart your web server and that should be it.

Here’s a quick sample code to get you started.

$uid,
“PWD”=>$pwd,
“Database”=>”database_name”
);
$conn = sqlsrv_connect($serverName, $connectionInfo);

if ($conn === false) {
echo “ERROR: DB Connection”;
die(print_r(sqlsrv_errors(), true));

}
$stmt = sqlsrv_query($conn, “SELECT * FROM table”);

if ($stmt) {
while ($row = sqlsrv_fetch_array($stmt)) {
echo $row[0].’
’;
}
}
?>

That should do it. I have only tested this on Windows 7 Professional (32bit), MSSQL 2005 (32bit) Standard on a remote Windows 2008 Server Standard R2, PHP5.3.3, Apache2.2.15, and driver version 1.1 (version 2 is now available) . Make sure your MSSQL server can accept remote connections if it is on a different server than your web server. The above instructions shouldn’t be too different on other versions.

If you have a phpinfo() page, you will see the image below.

sqlsrv_phpini

Hope this helps you get started. Happy coding.

Advertisements

#Problem:
We have .php file but we want to call it by .aspx extension in request url.

#Platform:
Uniform Server [3.5-Apollo]
Apache/2.0.59 (Win32) DAV/2 PHP/5.2.3

Solution:
In W:/usr/local/apache2/usr/local/apache2/conf/httpd.conf In Line: 294

===============================================
AddType application/x-httpd-php .phtml .php3 .php

add [.aspx] after it ->

AddType application/x-httpd-php .phtml .php3 .php .aspx
================================================
Then, change the desired .php file’s extension to .aspx without changing the php code.

And don’t forget to restart your uniserver.

tada! thats it!
Now you can simply use your php code like asp. 🙂

Hello world!

Welcome to WordPress.com. After you read this, you should delete and write your own post, with a new title above. Or hit Add New on the left (of the admin dashboard) to start a fresh post.

Here are some suggestions for your first post.

  1. You can find new ideas for what to blog about by reading the Daily Post.
  2. Add PressThis to your browser. It creates a new blog post for you about any interesting  page you read on the web.
  3. Make some changes to this page, and then hit preview on the right. You can alway preview any post or edit you before you share it to the world.