problem with odbc, mysql and placeholders

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



I am running into a problem using placeholders in a SELECT statement using odbc_prepare and odbc_execute with a mysql driver from php (version numbers, etc. after the code sample). The following code works just fine for postgresql, but not for mysql:

#!/usr/bin/php

<?php

$conn = odbc_connect('tstdb', 'xxxxx', 'yyyyy');
if ($conn == 0) {
echo("connect failed");
$sqlerr = odbc_errormsg($conn);
echo($sqlerr);
}
$stmt = odbc_prepare($conn, 'SELECT firstname, lastname FROM tst where id=?');
$result = odbc_execute($stmt, array(1));
if (!$result) {
echo("SELECT failed");
$sqlerr = odbc_errormsg($conn);
echo($sqlerr);
}
while (odbc_fetch_into($stmt, $row)) {
print $row[0];
print $row[1];
print "\n";
}
?>


With postgres i get the firstname and lastname as expected, but with mysql, i get some kind of gibberish (stdn_u) ... another interesting thing is that if I change the prepare to use 'where id=1', it works fine for mysql (and postgres for that matter). There is nothing tricky about the table (int id and varchar(20) for the names) and I can do all of this kind of stuff using ODBC from C (unixODBC) with both database systems. Also, UPDATEs using placeholders seem to work fine for MySQL also ...

I understand that this may not be a problem with the php odbc code but instead with one of the other layers ... how would i narrow that down? Any other places that I could post this question that might be better than here?

I get substantially the same results on an FC3 and a RH9 linux box with the following versions:

FC3: php-4.3.10-3.2, php-odbc-4.3.10-3.2, unixODBC-2.2.9-1, MyODBC-2.50.39-19.1, mysql-3.23.58-14

RH9: php-4.2.2-17, php-odbc-4.2.2-17, unixODBC-2.2.3-6, MyODBC-2.50.39-11, mysql-3.23.54a-11

thanks in advance for any help you can provide!

jake

--
Jake Edge - jake@xxxxxxxxx - http://www.edge2.net

--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [PHP Users]     [Postgresql Discussion]     [Kernel Newbies]     [Postgresql]     [Yosemite News]

  Powered by Linux