KNOWLEDGE BASE
Log In    |    Knowledge Base    |    4D Home
Tech Tip: Troubleshooting SQL Query Problems when connecting with PDO_4D
PRODUCT: 4D | VERSION: 12.1 | PLATFORM: Mac & Win
Published On: March 24, 2011

When experiencing problems querying a 4D database through PDO_4D, it is a good test to try your SQL request from 4D itself to make sure the request is valid.

First, from within the targeted 4D database you can test your SQL statement like this example:

Begin SQL
SELECT foo FROM bar INTO :$out
End SQL
ALERT("out: " + String($out))


You will then detect if the request is supported by the 4D SQL engine.

If the SQL statement works from within the targeted 4D database, then you should test from a remote 4D application using SQL LOGIN.

Next, from a remote 4D application, use "SQL Login" before "Begin SQL" like this example:

SQL Login($4D_ODBC_DSN; $login; $password)
Begin SQL
SELECT foo FROM bar INTO :$out
End SQL
ALERT("out: " + String($out))


Note: Make sure to use the correct DSN for your server.

Doing this will detect if the problems come from authentication or from the communication protocol.

If it worked from both of these methods, and doesn't from PDO_4D, then the problem comes from either the PHP code or the PDO_4D driver.

Don't forget to use try/catch and test the result of the PDO error messages:




These same steps are also useful for troubleshooting issues with executing SQL Statements from other ODBC applications as well. If the SQL statement is not supported by the 4D SQL Engine it will not work over ODBC.

See Also: