开发者

ODBC Connection String for PHP with Obscure Driver

I'm attempting to connect to a database via ODBC, and I am finding no help through Google/the internet.

Our ERP uses OMNIS as a framework, which provides an ODBC driv开发者_JAVA技巧er for querying OMNIS' proprietary database outside of the program. I've created the driver and DSN, but I cannot begin manipulating data or sending queries with PHP.

The driver appears in the ODBC connection manager as "OMNIS ODBC Driver" - I've tried a multitude of connection strings, but cannot seem to get it to go.

The DSN is located at C:\Test.dsn. Once again, the driver appears as OMNIS ODBC Driver. Any help is much, much appreciated.


Answer:

These instructions assume that Apache web server has already been set up on the host server.

Operating System: Windows Server 2003 Web Server: Apache 2 (WAMP www.wamp.com)

1. Download and install the Omnis ODBC Driver for Windows Non-Unicode driver (http://www.tigerlogic.com/tigerlogic/omnis/download/tools.js

2. Create a SYSTEM Data Source for your data file: -Start Menu > Administrative Tools > Data Sources -Choose the “System DSN” tab -Click Add -From the list of drivers choose “Omnis ODBC Driver” -Click Finish -Fill in the Data Source Name, Description, and Authentication credentials Important: Remember the Data Source Name EXACTLY. This is the name of the data source that will be used to connect to the database. -Choose the data file. -Save -The Data Source has now been registered with the operating system and is ready for use.

3. In your web root directory, create a new file name odbc_test.php .

Use the following sample code to test the data connection.

<?php

/*My data source is named PFDSN, so that is what I will be using in this example
   Make sure you use the exact name of the data source created in step 2.
*/
$conn = odbc_connect('PFDSN',' ',' ');  //the connection to the data file
$sql = 'select * from INVOICES';    //query string
$result = odbc_exec($conn,$sql); //execute the query
$while($data[] = odbc_fetch_array($result)); //loop through the result set
odbc_free_result($result); //unallocate the result set
odbc_close($conn); //because this is good practice

print_r($data);
?>

Save and close the file. Navigate to the http://localhost/odbc_test.php (or wherever the file is located).

If the connection was successful the page will display a dump of all the data pulled from the invoices table.

If it doesn't work, check to make sure that you have the correct DSN name in the connection string.
If the connection string is correct and it still doesn't work, there is a chance that PHP isn't configured with the ODBC module. However, you should note that since PHP 5 (in Windows) the ODBC module is enabled by default.

Tragically, at the time of this writing, Tiger Logic does not provide a Linux/Unix ODBC driver. Hopefully they come to their senses and realize that Windows sucks.

The End.


I ended up opening cloning the database to SQL and using that method. It was far too much of a pain to try to get the OMNIS ODBC Driver working.


I was able to connect using such DSN:

odbc:DRIVER=OMNIS;DataFilePath=C:\import\average.df1
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜