PHP and remote Sybase database

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.

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!

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

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!

What PDO exception are you getting when connecting?

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

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

Sponsor our Newsletter | Privacy Policy | Terms of Service