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

2

7

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.

Selfannihilation answered 28/6, 2013 at 22:5 Comment(1)
Have you seen this? Driver={SQL Server};Genuflect
A
9

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.

Afterpiece answered 1/7, 2013 at 7:55 Comment(1)
Thank you. On Windows 10 it is found at C:\Windows\ODBCINST.INIMunicipalize
M
4

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.

Miniaturist answered 10/10, 2020 at 21:25 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.