I'm attempting to use the PHP PDO ODBC driver to connect to a SQL Anywhere Database: <?php $host = "EnergyManagementDev"; $db = "EnergyManagementDev"; $user = "dba"; $pass = "sql"; try { $db = new PDO("odbc:Driver={SQL Anywhere 12};Server={$host};Database={$db};Uid={$user};Pwd={$pass};LOG=C:\MyClient.Log", $user, $pass); $db = null; //close the connections } catch(PDOException $e) { echo $e->getMessage(); } ?> The ODBC Data Source Administrator screen captures are below ("Test Connection" is successful): But I get the following error: SQLSTATE[08001] SQLDriverConnect: -100 [Sybase][ODBC Driver][SQL Anywhere]Database server not found The log output from C:MyClient.Log is: 12:21:53 Attempting to connect using: UID=dba;PWD=********;DBN=EnergyManagementDev;ServerName=EnergyManagementDev;CON=SQL_DBC_40c8a90;LOG=C:\MyClient.Log 12:21:53 Attempting to connect to a running server... 12:21:53 Trying to start SharedMemory link ... 12:21:53 SharedMemory link started successfully 12:21:53 Attempting SharedMemory connection (no sasrv.ini cached address) 12:21:53 No named shared memory buffer found 12:21:53 Not attempting to autostart server 12:21:53 Cannot connect to server What am I doing wrong? |
I guess the connection is missing the information to connect to a network server (assuming that your client and the database engine are running on different machines). It seems that your PDO connection string supports the usual SQL Anywhere connection parameters, so you could add
to your connection string. Both parameters will express that you want to connect over TCP/IP instead just locally. For further diagnostis, you could also add ";LOG=C:MyClient.Log" - that should create a text file with messages, how the client library tries to find and (hopefully) connect to the database... Thanks Volker. I've edited the question to add the log output as suggested.
(05 Nov '12, 06:28)
MMacdonald
Replies hidden
Your link to connection parameters seems broken - 404?
(05 Nov '12, 06:29)
MMacdonald
Replies hidden
Apparently, the client just tries to connect locally via shared memory. Have you tried my suggestions - they should exactly solve the problem, i.e. making the client to connect via TCP/IP...
(05 Nov '12, 06:30)
Volker Barth
Thanks. It was only necessary to specify the host (in fact it didn't allow both to be specified - "The HOST and LINKS options cannot both be specified"). I'll post the working connection string to help future readers, and accept your answer.
(05 Nov '12, 06:45)
MMacdonald
Replies hidden
You are correct: The "or" in my suggestion list is meant as an "exclusive or" - natural languages are so ambigiuous:)
(05 Nov '12, 06:48)
Volker Barth
Thanks, I've corrected that.
(05 Nov '12, 06:51)
Volker Barth
|
Here is the working connection code after following the suggestions in Volker's answer. <?php $host = "EnergyManagementDev"; $db = "EnergyManagementDev"; $user = "dba"; $pass = "sql"; try { $db = new PDO("odbc:Driver={SQL Anywhere 12};Server={$host};Database={$db};Uid={$user};Pwd={$pass};Host=192.168.1.10", $user, $pass); $db = null; //close the connections } catch(PDOException $e) { echo $e->getMessage(); } ?> |
If you wanted to store the connection information in the Data Source, you can do that. To use that, you would need to change your connection string provide the DSN, UID and PWD:
This way, it would get the server name, database name and host information from the DSN. I haven't actually tried this from PHP, but it should work. There is a chance you will still need the Driver={SQL Anywhere 12} but I don't think you will. |