I’m not talking about MySQL, I’m talking about Microsoft SQL Server
I’ve been aware of PDO for quite some time now, standard mysql functions are dangerous and should be avoided.
http://php.net/manual/en/function.mysql-connect.php
But what about the MSSQL function in PHP? They are, for most purposes, identical sets of functions, but the PHP page describing mssql_* carries no warning of deprecation.
http://us.php.net/manual/en/function.mssql-connect.php
There are PDO drivers available for MSSQL, but they aren’t quite as readily available or used as the MySQL drivers.
Ideally, it looks to me like I should get them working and move from mssql_* to PDO like I have with MySQL, but is it as big of a priority?
Is there some hidden safety to MSSQL that means it’s exempt from all of the mysql_* hatred as of late? Or is its obscurity as a backend the only reason there hasn’t been more PDO encouragement?
2
The MSSQL_*
and MySQL_*
families of functions share a common interface (i.e. similar naming), for convenience (if you know one’s functions, then you know the other’s) but that’s where the similarities stop.
And… there’s no hatred for the MySQL_*
family, it’s not “dangerous”, its use is discouraged as it’s using an older MySQL API that’s no longer relevant (except for legacy applications). Right now (PHP 5.4) MySQL_*
isn’t actually deprecated, using its functions doesn’t even raise an E_DEPRECATED error, but the extension is not actively developed, only maintained (bug fixes only, and even them are not high priority). We don’t know when the functions will be actually deprecated, but the usual process is that in a future version using them will raise an E_DEPRECATED error, and at an even later version the extension will not be available as part of the default installation and will no longer be maintained.
I don’t know what you mean when you say that MSSQL drivers aren’t readily available, but PHP no longer bundles MySQL client libraries since the first iteration of PHP 5.0. Client libraries are essential for any database, as PHP’s extensions are for the most part just wrappers of the client libraries. You’ll have to install the client libraries yourself for both MySQL and MSSSQL, and perhaps you haven’t noticed that yet because you are using a LAMP or WAMP bundle that installs everything for you. Still, in a vanilla setup the database’s client libraries must be installed separately.
PDO offers a mostly database agnostic interface, however it’s completely up to you whether you are going to use it or use MSSQL_*
. If you are working with different databases, not necessarily in the same project, PDO might be the better choice as you’d have to familiarize yourself with one interface. And if your project uses multiple database then PDO is the clear winner. Personally I’ve moved on to PDO for all my database needs, and never looked back.
To summarize:
MSSQL_*
andMySQL_*
share a common interface for convenience, nothing more, they are just wrappers to their respective database client libraries.MySQL_*
soon won’t be available, butMSSQL_*
will.- Both PDO and
MSSQL_*
are valid choices for working with SQL Server.
6