#30703 [Opn->Bgs]: Strange behaviour of mysqli_stmt_prepare()

From: Date: Sat, 06 Nov 2004 16:23:26 +0000
Subject: #30703 [Opn->Bgs]: Strange behaviour of mysqli_stmt_prepare()
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-68756@lists.php.net to get a copy of this message
 ID:               30703
 Updated by:       georg@php.net
 Reported By:      khru3l at gmail dot com
-Status:           Open
+Status:           Bogus
 Bug Type:         MySQLi related
 Operating System: Windows XP Coporate + SP2
 PHP Version:      5.0.2
 New Comment:

5.0.1a is a preview version and very old. Use the 5.0.2 
versions from bk tree or snaps.mysql.com. 
 
Works fine with MySQL 5.0.2: 
 
georg@beethoven:~/work/php/test> php -f 30703.php 
1 
2 
3 
4 
Array 
( 
    [pstat_Id] => 1 
) 
Array 
( 
    [pstat_Id] => 2 
) 
Array 
( 
    [pstat_Id] => 3 
) 
Array 
( 
    [pstat_Id] => 4 
) 
 


Previous Comments:
------------------------------------------------------------------------

[2004-11-06 15:35:54] khru3l at gmail dot com

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 this bug report at http://bugs.php.net/?id=30703&edit=1


Thread (2 messages)

« previous php.bugs (#68756) next »