I came across this weird issue using odbc_prepare to prepare a SQL statement with ? in place for the parameters. The query would odbc_prepare “successfully” and the odbc_execute would return “true”, but when i tried to fetch the row nothing came back. I eventually figured out that because my parameter was only 5 characters instead of 6 characters that was the reason the query wasn’t pulling back the records I was expecting.

PHP Code

[code language=”php”]
$queryToPrepare = "SELECT * FROM MYLIB.TABLE WHERE DATE >= ?"
array_push($queryParameters, str_pad($date, 6, " ", STR_PAD_LEFT));
$preparedQuery = odbc_prepare($this->connection_id, $queryToPrepare);
$success = odbc_execute($preparedQuery, $parameters);
if (odbc_fetch_row($result))
{
echo odbc_result($result, "MYFIELD");
}
[/code]