Using PHP with MS SQL Server - Optional Packages
(Page 3 of 5 )
The PEAR DB package is incredibly useful for the aspiring cross-platform developer. Since using PHP with MS SQL is not only cross platform but cross culture, it makes a lot of sense to use it when you're looking at a PHP/MS SQL combination. DB is one of the core modules included in PEAR, so if you've already installed PEAR you should have DB available.
If you haven't installed PEAR you can get it from http://pear.php.net. Install it in a common folder on your server (or under your server account) and make sure that it's included in the PHP Include path. If you don't have access to the php.ini file, you can just copy the PEAR distribution into the root of your application, although this gets a little cumbersome.
Using DB
DB is a class hierarchy that lets you use different database engines without changing your PHP code. It makes using one engine more or less the same as any other, and saves you needing to learn the peculiarities of any specific engine. Other articles have covered the use of the DB module fairly well, so I won't go into great detail here. There are some things that you should be aware of though that differ slightly from the MySQL usage that you might be familiar with.
First, if you're working on a UNIX system or your windows build uses Sybase libraries instead of mssql, you'll need to specify the port number to connect to. SQL Server by default listens on port 1433. If you're using the windows binary distribution and have enabled the mssql module that ships with it, you don't need the port number unless a non-standard port number is being used.
The second thing is that you need to be aware of the syntax for using a stored procedure. While stored procedures aren't necessary to use SQL Server, they are a very commonly used feature and it would be a shame not to take advantage of the power that they offer. The syntax is "EXECUTE procedure_name @variable1 = 'value1', @variable2 = 'value2'".
Next: An Example >>
More MS SQL Server Articles
More By Clay Dowling