For Programmers: Free Programming Magazines  


Home > Archive > PHP DB > April 2007 > PDO prepared statements sometimes returns empty resultset









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author PDO prepared statements sometimes returns empty resultset
Emil Ivanov

2007-04-23, 6:57 pm

Hi,

I'm trying to get some data form a MySQL db using PDO and prepared
statement, but I noticed that sometimes it fetches an empty result set,
but sometimes does what it's supposed to do - returns the whole result set.

The environment is WinXP SP2 Home, apache 2.2.4, PHP 5.2.1 and MySQL 5.0.27.

Here is some code:

$db = new PDO(
'mysql:host=localhost;dbname=name_of_db'
,
'user_name',
'password',
array (
PDO::ATTR_PERSISTENT => true
)
);
$db->query('SET CHARACTER SET utf8');
$stmt = $db->prepare("CALL sp_get_all_currencies(:lang_id)");
$stmt->bindValue(':lang_id', $currenctLanguageId, PDO::PARAM_INT);
$stmt->execute();
$currencies = $stmt->fetchAll();

So here, $currencies sometimes is an empty array, and after a refresh of
the browser it populates.

I also noticed that it works ok with $db->query(), but query doesn't
have that fancy param binding (I think).

Is there some caching or something... Is this a bug in PHP or I'm not
getting the picture right?

Regards,
Emil Ivanov
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com