Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 364
EGr Avatar asked Jun 28 '13 22:06

EGr


People also ask

How do I know which ODBC driver I have?

To check the ODBC SQL Server driver version (32-bit ODBC)In the ODBC Data Source Administrator, click the Drivers tab. Information for the Microsoft SQL Server entry is displayed in the Version column.

Does PHP use ODBC?

ODBC is a connector that makes PHP development "database connector-agnostic." It uses functions like odbc_query() against databases like MySQL, PostgreSQL, SQLite, Microsoft SQL Server®, IBM® DB2®, Sybase, OpenLink Virtuoso, FileMaker, and Microsoft Office® Access®.

What does ODBC do in context with PHP in PHP?

ODBC is an API that allows you to connect to a data source, such as PostgreSQL, Oracle, MySQL, MongoDB or SQL Server, using standard PHP functions and Devart ODBC Drivers. You can use PHP with databases via a connector to deliver HTML to a web browser that requests a resource.


2 Answers

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.

like image 152
bohica Avatar answered Nov 14 '22 20:11

bohica


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.

like image 42
BugLogic Avatar answered Nov 14 '22 20:11

BugLogic