9

I'm trying to connect to a Sybase database with PHP5. I believe I've successfully compiled PHP with PDO_DBLIB, as phpinfo() lists dblib under PDO drivers, and freetds as the pdo_dblib flavour.

However, when I try to test a connection, I get an error reading:

'PDOException' with message 'could not find driver'

I'm trying to connect to a server on my LAN with this code:

$dbh = new PDO("sybase:host=192.168.1.xxx;dbname=[database-name]", '[user]', '[pass]');

Any suggestions would be greatly appreciated!

Shoe
  • 74,840
  • 36
  • 166
  • 272
zwiebelspaetzle
  • 250
  • 1
  • 3
  • 8
  • It seems you don't have driver installed and enabled in php.ini You can try this experimental driver: http://php.net/manual/en/ref.pdo-dblib.php – shark555 Jan 18 '13 at 22:19
  • Did you find a solution? I'm having trouble connecting to the sybase server myself. – Leccho Jul 15 '20 at 13:37

3 Answers3

2

You should use dblib instead of sybase, like this:

$dbh = new PDO("dblib:host=192.168.1.xxx;dbname=[database-name]", '[user]', '[pass]');
Undo
  • 25,519
  • 37
  • 106
  • 129
gumaterror
  • 96
  • 5
-1

PDO wouldn't work, or at least there is no PDO Sybase support for php. On Windows, you can use ODBC, and PDO_SQLSRV or PDO_ODBC, it might sound weird, but it should work.

Second option and I would recommend it, is to connect directly to Sybase (SqlAnywhere), but you need to install SQL Anywhere PHP Module

Zdenek Machek
  • 1,758
  • 1
  • 20
  • 30
  • Zdenek Machek, thanks for the link to the SQL Anywhere PHP Module. – zwiebelspaetzle Jan 23 '13 at 08:04
  • I'm trying to use the SQL Anywhere PHP Module, but when I start httpd, I get this error: "The SQLAnywhere client libraries could not be loaded. Please ensure that libdbcapi_r.so can be found in your LD_LIBRARY_PATH environment variable." I've added "SetEnv LD_LIBRARY_PATH /opt/sqlanywhere12/lib64" to my httpd.conf file. However, phpinfo still shows the Apache Environment LD_LIBRARY_PATH as /usr/local/apache2/lib. Any suggestions? – zwiebelspaetzle Jan 23 '13 at 08:14
  • Yes, on your machine needs to be installed Sybase SqlAnywhere or at least SqlAnywhere client and this library needs to be added to system path, see "echo $PATH" – Zdenek Machek Jan 23 '13 at 14:01
  • Thanks for the reply. I've installed SQL Anywhere 12 Web edition, and libdbcapi_r.so is sitting in /opt/sqlanywhere12/lib64. I've added `"/opt/sqlanywhere12/lib64"` to my system path (it shows when I "echo $PATH".) However, I still get the same error from sqlanywhere. I understand that LD_LIBRARY_PATH is different from the system path, but I cannot find a way to change the LD_LIBRARY_PATH listed under Apache Environment phpinfo(). The /opt/sqlanywhere12/bin64/sa_config.sh script doesn't seem to affect Apache. Is this variable indeed what I need to change? Many Thanks! – zwiebelspaetzle Jan 23 '13 at 18:34
  • I tried to use the SQL Anywhere PHP Module with PHP5 and It seems that is not possible. I got an error that the module and php are compiled with different module API – agmezr Mar 12 '14 at 17:35
  • Then only solution is to compile extension from source code. Try Vagrant, these sort of things is sometimes better to test in virtual machine. – Zdenek Machek Mar 12 '14 at 22:24
  • This answer is wrong. PDO_DBLIB specifically states it is for connecting to Sybase: *PDO_DBLIB is a driver that implements the PHP Data Objects (PDO) interface to enable access from PHP to Microsoft SQL Server and Sybase databases through the FreeTDS library.* – dossy Oct 05 '18 at 01:35
-1

If you are using Ubuntu you can put the LD_LIBRARY_PATH inside envvars and it seems to read... still trying to find a way to get it to stick on RHEL based systems... Windows I am not too sure about I would hope you could set a system wide variable under

my computer -> properties -> advanced options

If are using RHEL based systems it might be better to include the: export LD_LIBRARY_PATH=/path/to/library/ in the httpd restart script (check to see if it loads /etc/sysconfig/httpd and if so add the line in there - now restart apache and you should see some activity.

Akj
  • 7,038
  • 3
  • 28
  • 40
YFP
  • 331
  • 3
  • 8