Connecting Php with SQLServer 2000

$server = "";
$database = "GERENCIA";
$user = "sa";
$password = "";
$conexión = odbc_connect("Driver={SQL Server Native Client 10.0};Server=$server;Database=$database;", $user, $password);

I am looking to connect to a MS SQL Server 2000 server, using odbc_connect , but I think it is not detecting the driver.

What is the correct way to install the driver and make the connection? Or what do I lack?:


Fatal error: Uncaught Error: Call to undefined function odbc_connect () in C: \ xampp \ htdocs \ atcrete \ config \ sqlsrvr.php: 17 Stack trace: # 0 {main} thrown in C: \ xampp \ htdocs \ atcreporte \ config \ sqlsrvr.php on line 17

asked by Armando Arellano 18.01.2018 в 03:46

1 answer


Description of the problem

Error message:


Fatal error: Uncaught Error: Call to undefined function odbc_connect() in ...


The odbc_connect function does not exist because the required extension is not loaded.

PHP / ODBC installation on Linux

Depending on the Linux distribution used, it will be necessary to use the specific package manager of each one to install the necessary one.

In the case of distributions based on RedHat (such as CentOS, Oracle Linux, etc), Debian (Ubuntu, Xubuntu, Guadalinex, etc.) and SUSE (OpenSUSE) the package is called php-odbc and the command needed to perform the installation (as root ) varies depending on the distribution:

apt-get install php-odbc    # Debian Stretch / Ubuntu 16.04 LTS / etc
yum install php-odbc        # Oracle Linux 7 / Fedora 27 / etc
zypper install php5-odbc    # OpenSUSE 42.3

PHP / ODBC installation in Windows

Depending on the package or distribution downloaded (such as XAMPP or WAMP ) everything necessary is included but is not activated by default.

To activate the PHP / ODBC extensions you must add the following line in the file php.ini :


After doing so, you must restart the apache server for the changes to take effect.

Name of the ODBC drivers available in Windows

To obtain a list of available drivers installed in Windows, you must inspect the following registry key:


To obtain a list from the command line, the following instruction can be executed:


Whose sample output would be:

    SQL Server    REG_SZ    Installed
    SQL Native Client    REG_SZ    Installed
    IBM DB2 ODBC DRIVER - DB2COPY1    REG_SZ    Installed
    IBM DB2 ODBC DRIVER    REG_SZ    Installed
    BMC ODBC for PostgreSQL ANSI (Default)    REG_SZ    Installed
    BMC ODBC for PostgreSQL UNICODE (Default)    REG_SZ    Installed
    BMC ODBC for Oracle (Default)    REG_SZ    Installed

So your connection string should be:

$conexión = odbc_connect(
    "Driver={SQL Server};Server=$server;Database=$database;",

You can also view the available and the driver version through "ODBC Data Sources (32/64 bits)" in the "Drivers" tab:

answered by 19.01.2018 / 08:34