简体   繁体   中英

How can I determine what drivers are available to use with odbc in php (on a linux system)?

In PHP scripts, it looks like this is how you connect to an odbc database:

$connection = odbc_connect("Driver={SQL Server Native Client 10.0};Server=$server;Database=$database;", $user, $password);

The problem I'm having is that I don't know what to use for "Driver=". What I put in there is what was provided for another script I saw. In my script, all I do is try to connect using this line, but I get the following error:

Warning: odbc_connect(): SQL error: [unixODBC][Driver Manager]Data source name not found, and no default driver specified, SQL state IM002 in SQLConnect in /srv/www/htdocs/site/test.php on line 8

From what I can tell, it looks like the driver I specified is incorrect. The database I am trying to connect to is an MSSQL database, and I only plan to query for information from it. Is there a way to list the database drivers I have available on my system? I've never had to install/configure any drivers like this before (I've never done anything like this; all php work I've done in the past has been with MySQL). Also, I don't want to compile other software onto my system (if possible); I would prefer to install all packages from repos.

You should have a file called odbcinst.ini (probably in /etc or /usr/local/etc but you can locate it with the command odbcinst -j). This file defines your ODBC drivers. Each driver is named within the [] in each section.

You might find Linux ODBC useful as it contains a thorough explanation of unixODBC, how it works and how to define data sources.

The question was how to find the list of ODBC drivers available. In the command line run:

    odbcinst -q -d

This will list the drivers if you don't know already.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM