I'm having a very weird problem with $result->fetch_assoc(). Here are two
very simplified examples. One uses a prepared statement (although for this
exercise I'm not using any bound parameters, my results aren't affected);
the other example uses $db->query(). Look at the retrieved $row.

<?php
$db = new mysqli('host.giiexpress.com', 'giiexpr', 'xxxx', 'giiexpr_db')
        or die('connect failed');
$select = 'SELECT prod_num, prod_title FROM prod WHERE prod_num = 53851 and
prod_title != "snort"';
$s = $db->prepare($select)
        or die($db->error);
$s->execute()
        or die($db->error);
$result = $db->store_result()
        or die($db->error);
echo '$result: ' . "\n"; var_dump($result);
$num_rows = $result->num_rows;
echo '$num_rows: ' . "\n"; var_dump($num_rows);
$row = $result->fetch_assoc()
        or die($db->error);
echo '$row: ' . "\n"; var_dump($row);
?>

This one gives me empty strings:

$result:
object(mysqli_result)#3 (0) {
}
$num_rows:
int(1)
$row:
array(2) {
  ["prod_num"]=>
  string(0) ""
  ["prod_title"]=>
  string(0) ""
}

If I simply use $db->query(), I get the proper results:

<?php
$db = new mysqli('host.giiexpress.com', 'giiexpr', 'xxxx', 'giiexpr_db
        or die('connect failed');
$select = 'SELECT prod_num, prod_title FROM prod WHERE prod_num = 53851 and
prod_title != "snort"';

$result = $db->query($select);

echo '$result: ' . "\n"; var_dump($result);
$num_rows = $result->num_rows;
echo '$num_rows: ' . "\n"; var_dump($num_rows);
$row = mysqli_fetch_assoc($result);
echo '$row: ' . "\n"; var_dump($row);
?>

$result:
object(mysqli_result)#2 (0) {
}
$num_rows:
int(1)
$row:
array(2) {
  ["prod_num"]=>
  string(5) "53851"
  ["prod_title"]=>
  string(41) "2007 U.S. Consumer Digital Imaging Survey"
}

I've tried this on Windows using PHP 5.2.2, and on CentOS using 5.0.4. I get
the same results.

Regards,

Jerry Schwartz
The Infoshop by Global Information Incorporated
195 Farmington Ave.
Farmington, CT 06032

860.674.8796 / FAX: 860.674.8341

www.the-infoshop.com <http://www.the-infoshop.com/>
www.giiexpress.com <http://www.giiexpress.com/>
www.etudes-marche.com




-- 
MySQL General Mailing List
For list archives: http://lists.mysql.com/mysql
To unsubscribe:    http://lists.mysql.com/[EMAIL PROTECTED]

Reply via email to