I’m trying connect to MS SQL Server with PHP with DBX. with a phpinf(), i can note that dbx is enabled:
dbx
dbx support enabled
dbx version 1.0.0
supported databases MySQL ODBC PostgreSQL Microsoft SQL Server FrontBase Oracle 8 (oci8) Sybase-CT.
But when i try connect, appear this error:
Warning: dbx: module 'mssql' not loaded.
this is the code:
dbx_connect("mssql","host","database","user","password");
Any idea to solve this?
My recommendation is going to be not using DBX. It’s a dead module and should not be used by modern code.
DBX was removed from standard PHP in version 5.1. If you have it installed, that means someone went out of their way to install it as a PECL module, or you’re using a very old PHP version.
On the requirements page, it states:
The only module DBX supports for talking to MS SQL Server is the old
mssql_family. That extension is no longer available in Windows PHP versions 5.3 or later.If you’re on Linux, and are using an OS-provided PHP release, you might be able to get it installed. Look for
php-mssqlorphp53-mssql. It might also show up when you search package descriptions for “FreeTDS.” If no packages are available, you may be in for a world of pain. Gettingmssql_compiled and installed is quite a bear.However, there are much better alternatives.
The goal of DBX was to present a unified set of functions that let you speak to a multitude of the existing PHP database adapters. That role is now filled by PDO. If you’re on Windows, you should use PDO_SQLSRV. If you aren’t on Windows, you could use PDO_DBLIB (which uses the same backend as the
mssql_family) or PDO_ODBC. If you’ve never used PDO before, there are a few good tutorials. That one is targeted at MySQL users, but it still applies to other databases.If the code you’ve written is only ever intended to run on MS SQL Server, and you’re running PHP on Windows, then you could also consider writing it using the
sqlsrv_family of functions instead.