Reputation: 806
Having this PHP code:
$sql = "SELECT * FROM users WHERE name = ?";
$params = array('admin');
$result = odbc_prepare($link, $sql);
if (!$result) {
die(odbc_errormsg());
}
else {
if (!odbc_execute($result, $parameters)) {
die(odbc_errormsg());
}
}
I get this:
Warning: odbc_execute() [function.odbc-execute]: SQL error: Failed to fetch error message, SQL state HY000 in SQLExecute in [...]
However if I do this:
$sql = "SELECT * FROM users WHERE name = 'admin'";
$params = array();
$result = odbc_prepare($link, $sql);
if (!$result) {
die(odbc_errormsg());
}
else {
if (!odbc_execute($result, $parameters)) {
die(odbc_errormsg());
}
}
I get the expected result. What could it be?
My code is running on Ubuntu Server, using UnixODBC and FreeTDS, connecting to a MSSQL Server 2008.
Regards!
Upvotes: 2
Views: 2516
Reputation: 6240
Instead of using the odbc_* functions why don't you use PDO? It should handle parameterized queries internally and pass along the SQL statement to the driver (FreeTDS in this case).
Upvotes: 1