From:             khru3l at gmail dot com
Operating system: Windows XP Coporate + SP2
PHP version:      5.0.2
PHP Bug Type:     MySQLi related
Bug description:  Strange behaviour of mysqli_stmt_prepare()

Description:
------------
Enviroment: 
- Apache 2.0.52 + PHP 5.0.2 + MySQL 5.0.1a @ Windows XP + SP2


I am using the following MyISAM table, named <poll_statistic>:

CREATE TABLE poll_statistic (
        pstat_Id MEDIUMINT(7) UNSIGNED NOT NULL AUTO_INCREMENT, 
        pstat_Parent SMALLINT(5) UNSIGNED NOT NULL,
        pstat_Ip VARCHAR(8) NOT NULL,
        pstat_Date DATETIME DEFAULT '0000-00-00 00:00:00',
        KEY key_Id (pstat_Id),
        PRIMARY KEY(pstat_Ip, pstat_ParentId)
);

+----------+--------------+----------+---------------------+
| pstat_Id | pstat_Parent | pstat_Ip | pstat_Date          | 
+----------+--------------+----------+---------------------+
|        1 |            2 | 7f000001 | 2004-11-06 12:19:57 |    
|        2 |            4 | 7f000001 | 2004-11-06 12:19:57 |
|        3 |            5 | 7f000001 | 2004-11-06 12:19:57 |
|        4 |            7 | 7f000001 | 2004-11-06 12:19:57 |
+----------+--------------+----------+---------------------+

For the SAME sql query: "SELECT pstat_Id FROM poll_statistic", I get two
different results. Using prepared statements the query returns 0 all the
time instead of the actual value hold by <pstat_Id> column. IF I change
the SQL Query to: "SELECT pstat_Parent FROM poll_statistic" or "SELECT
pstat_Ip FROM poll_statistic" everything works out fine. Back on selecting
pstat_Id, the returned value is 0. 

I'd really like to know if it's my fault or if there is a problem with
mysqli. I have restarted apache/mysql several times, but with the same
result.

Reproduce code:
---------------
<?php
$mysqli = new mysqli("localhost", "root", "password", "vote");
//Method I
$query = "SELECT pstat_Id FROM poll_statistic";
if ($stmt = $mysqli->prepare($query)) {
   $stmt->execute();
   $stmt->bind_result($pid);
   while ($stmt->fetch()) { printf ("%s\n", $pid); }   
   $stmt->close();
}       
//Method II
if ($result = $mysqli->query($query)) {
   while ($row = $result->fetch_array(MYSQLI_ASSOC)) {       
print_r($row); }
   $result->close();
}
$mysqli->close();

Expected result:
----------------
Method I:
1
2
3
4

Method II:
Array ( [pstat_Id] => 1 )
Array ( [pstat_Id] => 2 )
Array ( [pstat_Id] => 3 )
Array ( [pstat_Id] => 4 )

Actual result:
--------------
Method I:
0
0
0
0

Method II:
Array ( [pstat_Id] => 1 )
Array ( [pstat_Id] => 2 )
Array ( [pstat_Id] => 3 )
Array ( [pstat_Id] => 4 )

-- 
Edit bug report at http://bugs.php.net/?id=30703&edit=1
-- 
Try a CVS snapshot (php4):   http://bugs.php.net/fix.php?id=30703&r=trysnapshot4
Try a CVS snapshot (php5.0): http://bugs.php.net/fix.php?id=30703&r=trysnapshot50
Try a CVS snapshot (php5.1): http://bugs.php.net/fix.php?id=30703&r=trysnapshot51
Fixed in CVS:                http://bugs.php.net/fix.php?id=30703&r=fixedcvs
Fixed in release:            http://bugs.php.net/fix.php?id=30703&r=alreadyfixed
Need backtrace:              http://bugs.php.net/fix.php?id=30703&r=needtrace
Need Reproduce Script:       http://bugs.php.net/fix.php?id=30703&r=needscript
Try newer version:           http://bugs.php.net/fix.php?id=30703&r=oldversion
Not developer issue:         http://bugs.php.net/fix.php?id=30703&r=support
Expected behavior:           http://bugs.php.net/fix.php?id=30703&r=notwrong
Not enough info:             http://bugs.php.net/fix.php?id=30703&r=notenoughinfo
Submitted twice:             http://bugs.php.net/fix.php?id=30703&r=submittedtwice
register_globals:            http://bugs.php.net/fix.php?id=30703&r=globals
PHP 3 support discontinued:  http://bugs.php.net/fix.php?id=30703&r=php3
Daylight Savings:            http://bugs.php.net/fix.php?id=30703&r=dst
IIS Stability:               http://bugs.php.net/fix.php?id=30703&r=isapi
Install GNU Sed:             http://bugs.php.net/fix.php?id=30703&r=gnused
Floating point limitations:  http://bugs.php.net/fix.php?id=30703&r=float
MySQL Configuration Error:   http://bugs.php.net/fix.php?id=30703&r=mysqlcfg

Reply via email to