php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #32593 odbc with mysql SELECT with placeholders fails
Submitted: 2005-04-05 18:09 UTC Modified: 2005-06-21 01:00 UTC
From: jake at edge2 dot net Assigned:
Status: No Feedback Package: ODBC related
PHP Version: 5CVS, 4CVS (2005-04-14) OS: *
Private report: No CVE-ID: None
Have you experienced this issue?
Rate the importance of this bug to you:

 [2005-04-05 18:09 UTC] jake at edge2 dot net
Description:
------------
If I use placeholders (?) in a SELECT statement using odbc_prepare() and odbc_execute(), I get gibberish from the MySQL driver and it works correctly using the PostgreSQL driver.

If I change the query to "WHERE id=1", it works fine.  UPDATES using placeholders work fine for MySQL.

I am able to do the same queries in C using the same libraries for unixODBC and MyODBC (and postgres-odbc) and get correct results.  This may not be a PHP and/or PHP-odbc problem, but so far, it looks that way.

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


Reproduce code:
---------------
#!/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] . " " . $row[1] . "\n";   
}
?>


Expected result:
----------------
I expect to get the firstname and lastname from the database.  The table is an int id and varchar(20) for the names.

Actual result:
--------------
Some kind of junk:  "std n_u"

Postgres gives the correct result (firstname and lastname from the database)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2005-04-13 17:33 UTC] jake at edge2 dot net
got a newer version of the tgz file this morning, built it successfully (using ./configure --with-unixODBC=shared,/usr) and ran it like so:

[jake@anhinga php4-STABLE-200504131242]$ php -dextension_dir=`pwd`/ext ~/x.php

and got exactly the same results as before (correct from pgsql, junk (n_u nT0) from mysql)

I have also run into another problem, which may be related in that php-odbc does not seem to do quoting correctly for placeholders for either pgsql or mysql ... not sure if i should file a different bug or add it to this one ... it also occurs on this version of php
 [2005-06-13 11:11 UTC] sniper@php.net
Are you sure this isn't a bug with the Mysql ODBC driver?

 [2005-06-21 01:00 UTC] php-bugs at lists dot php dot net
No feedback was provided for this bug for over a week, so it is
being suspended automatically. If you are able to provide the
information that was originally requested, please do so and change
the status of the bug back to "Open".
 
PHP Copyright © 2001-2020 The PHP Group
All rights reserved.
Last updated: Sat Nov 28 08:01:23 2020 UTC