I can\'t for the life of me work out what\'s going on here. I have a query with placeholders but when I prepare and execute it the data I get back is garbage. If I take the placeholder out and replace it with the literal \'id\' everything works fine! Here\'s an example:
$params=array(78); // Primary key
$sh=odbc_prepare($db,\"SELECT id,forename,surname,dob FROM person WHERE id=?\");
odbc_execute($sh,$params);
while(odbc_fetch_into($sh,$row)) {
print \"<pre>\";
var_dump($row);
print \"</pre>\";
}
Our intranet server has the following setup:
Red Hat 7.2
Apache 1.3.20 (binary distrib)
MySQL 3.23.49a (binary distrib)
MyODBC 2.50.39 (uncustomized local build)
PHP 4.1.2 (uncustomized local build)
unixODBC 2.2.0 (uncustomized local build)
The above code should (and does) fetch 1 row. When I dump the array however I get the following:
array(4) {
[0]=>
&string(2) \"o_\"
[1]=>
string(6) \"lefsd\"
[2]=>
&string(8) \"0)\'@ro%\"
[3]=>
&string(10) \"1917-11-21\"
}
The string lengths are correct but the content isn\'t. With every refresh of the page the data changes (kinda looks like a string printed from C with a broken pointer). If I replace the placeholder with the value 78 I get the following:
array(4) {
[0]=>
&string(2) \"78\"
[1]=>
string(6) \"STEVEN\"
[2]=>
string(8) \"STEPHENS\"
[3]=>
string(10) \"1917-11-21\"
}
Everything works as it should. If I run the same code on a Windows server (same setup as intranet server) but connect to the same database the problem repeats itself. If, however, I change the MyODBC driver on the Windows box to version 3.50.02 the problem goes away. But, just to confuse the problem further, if I compile version 3.50.02 of the MyODBC driver on the Linux box, the problem remains. Eh?
It\'s not the database because I\'ve tried other instances and all the tables checkout OK.
Anyone got any bright ideas cos this one\'s bakin\' my noodle.
Dan.