Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Warning: dbx: module 'mssql' not loaded

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?

like image 722
chenio Avatar asked Oct 23 '22 00:10

chenio


1 Answers

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:

To be able to use a database with the dbx-module, the module must be either linked or loaded into PHP

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-mssql or php53-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. Getting mssql_ 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.

like image 140
Charles Avatar answered Oct 27 '22 10:10

Charles