php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #30703 Strange behaviour of mysqli_stmt_prepare()
Submitted: 2004-11-06 15:35 UTC Modified: 2004-11-06 17:23 UTC
From: khru3l at gmail dot com Assigned:
Status: Not a bug Package: MySQLi related
PHP Version: 5.0.2 OS: Windows XP Coporate + SP2
Private report: No CVE-ID: None
View Add Comment Developer Edit
Welcome! If you don't have a Git account, you can't do anything here.
You can add a comment by following this link or if you reported this bug, you can edit this bug over here.
(description)
Block user comment
Status: Assign to:
Package:
Bug Type:
Summary:
From: khru3l at gmail dot com
New email:
PHP Version: OS:

 

 [2004-11-06 15:35 UTC] 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 )

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-11-06 17:23 UTC] georg@php.net
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 
) 
 
 
PHP Copyright © 2001-2021 The PHP Group
All rights reserved.
Last updated: Fri Sep 17 13:03:37 2021 UTC