MS SQL Server 2008 with PHP

Post image of MS SQL Server 2008 with PHP
Filed in Author's Choice , Coding Tips , Database Systems , Programming 1 comments

I personally choose not to use Micro$oft products when it is possible, but sometimes the choice is not given. For these unfortunate who have to deal with SQL Server 2008 (or 2005), here is how to get around without too many swear words and avoid licensing costs.

Requirements

  1. Windows Vista, Windows 7 or Win XP
  2. .Net Framework 3.5 SP1
  3. Windows Installer 4.5
  4. Windows PowerShell 1.0
  5. MS Core XML Services (MSXML) 6.0

Note: In order to download windows Power Shell, you need to pass the genuine windows checking. You can still google for alternative download locations preventing the need for the checking. Power Shell also comes preinstalled from windows 7 including .Net framework 3.5 but it wont eliminate the need to download the service pack.
.
Setup SQL Server

  1. Download and install MS SQL Server Express 2008 with Advanced Services and choose the following options:
  2. Single instance Install (not clustered !)
  3. Name the instance “SQLExpress”
  4. In the options box choose “SQL Server”, and “Management Studio” (do not install full-text search, as it requires clustering)
  5. Set the Server Service Account Name to “NT AUTHORITY\NETWORK SERVICE”, auto
  6. Set the SQL Server Browser to “NT AUTHORITY\NETWORK SERVICE”, manual
  7. Choose mixed mode authentication
  8. Set SQL Server to listen on TCP port.
  9. Start “SQL Server Configuration Manager”
    • Network Configuration -> Protocols : enable “Named Pipes” and “TCP/IP”
    • Right-click “TCP/IP” -> Listen All = Yes”
    • In tab “IP addresses” -> Section IPAll -> TCP Dynamic Ports = 1433
    • Repeat these steps for SQL Native Client.
    • Restart SQL Server
  10. Create your database and set the owner to user ‘sa’, and change the user sa password.

Note: If you have an MSDN account, you can download SQLServer 2008 developer, this SQLServer have all the features of enterprise edition and only differ on licensing. You can also google for a store that sells the DVD for $47-$50.

Setup PHP

This assumes you have wamp installed, otherwise just change the path.

  1. Download the good version of ntwdblib.dll (2000.80.194.0)
  2. Overwrite C:\wamp\bin\apache\apache2.2.8\bin\ntwdblib.dll
  3. Overwrite C:\wamp\bin\php\php5.2.6\ntwdblib.dll
  4. Enable php_mssql.dll in php.ini
    extension=php_mssql.dll
  5. Restart Apache and test using the code below
    $server = 'BANGKOK\SQLEXPRESS';  // The format is "HOST\SERVERNAME[,PORT]"
    $username = 'sa';
    mssql_connect($server, $username, $password);

Note: WAMP was only recommend since it is easier to change the settings with no manual modification on your php.ini file. If you used windows 7 as the base operating system, you are required to download “SQLServer Service Pack 1″ to fix issues with SQLServer and windows 7.

The posted topic is inspired by a post made by David Lauzon which guide me on how to tackle the nightmare of using M$Sql and PHP together. For the record, I manage to connect MSSql and PHP in 7 days with no idea on what is wrong and even Visual Studio 2008 / Visual Studio 2010 have no success on connecting.

Posted by vhortex   @   4 August 2010 1 comments
Tags : , , , ,

1 Comments

Comments
Author Aug 7, 2010
3:17 am

To people that are reading my blog, some contents that I am going to write will be available to astahost only. Astahost is a great commnunity that offers free quality webhosting for free by contributing to the forum.

I used to be hosted at astahost 3 years ago, the reason that I stopped being hosted is the lost of interest on maintaining a website. Travel from Laguna and Manila which is around 56km daily exhausted me too much.

Leave a Comment

Previous Post
«
Next Post
»
© 2011 - 2012 Vhortex's Little Digital Journey PolkaDot designed by ZENVERSE

Optimized by SEO Ultimate