PHP and remote Sybase database

#1

Hi. I am trying to read from a remote Sybase db in a php script in my pc. I have the username, password, db name and the ip address and port where the database is located but I have no idea how to connect.

#2

Your only way is through PDO. There is (thankfully) a driver for it called dlib.

Connection format is:
[php]$dbh = new PDO (“dblib:hostname:port;dbname”,“username”,“pw”);[/php]

Once you are connected, use PDO as normal - it does the abstraction!

#3

Hi again. Thanks for the help. After searching a bit for the driver you said I found out this:

http://www.php.net/manual/en/ref.pdo-dblib.php

This extension is not available anymore on Windows with PHP 5.3 or later.

If it is not possible to use SqlSrv, you can use the PDO_ODBC driver to connect to Microsoft SQL Server and Sybase databases, as the native Windows DB-LIB is ancient, thread un-safe and no longer supported by Microsoft.

So I tried using this driver with the following line but, unsurprisingly, it doesn’t work.

[php]$connection=new PDO(“odbc:Driver={SYBASE ASE ODBC Driver};Server=ip,port;Database=name; Uid=user;Pwd=pass;”);[/php]

Any ideas of what might be wrong / what the connection string should be?

Thanks in advance!

#4

What PDO exception are you getting when connecting?

#5

I got this using try/catch :
SQLSTATE[IM002] SQLDriverConnect: 0 [Microsoft][ODBC Driver Manager] Data source name not found and no default driver specified

#6

Can you check on your server the ODBC drivers installed? This can be found in the Administration tools under ODBC sources.