PEAR is archived and read-only

This mirror preserves historical PEAR package releases and metadata so existing references remain available.

Home » Database » MDB2 » Bug #8426

Error on Empty Result Set

Details

Submitted2006-08-13 22:28 UTC
Fromtehjcon at gmail dot com
StatusNo Feedback
PackageMDB2
PHP Version5.1.4
OSDebian 3.4.3
Roadmaps(Not assigned)

Comments

[2006-08-13 22:28 UTC] tehjcon at gmail dot com

Description:
------------
This error was caused with the mysqli driver. PHP 5.1.4, MYSQL 5.0.22

Fatal error: MDB2 Error: Array in /(path_to_files)/includes/dbfs.php on line 50

Returns PEAR error class instead of NULL or '' When returning zero rows from $db->queryOne

Test script:
---------------
$sql = 'SELECT last_modified_time
FROM ' . FILES_TABLE . '
WHERE file_path = ' . $db->quote((string) $file_path);

$last_modified_time = $db->queryOne($sql);

if (PEAR::isError($last_modified_time))
{
var_dump($last_modified_time);
}

Expected result:
----------------
Nothing, no errors. I would expect that $last_modified_time is NULL when there are no rows that match the query.

Actual result:
--------------
$last_modified_time is a PEAR error class. The query works fine when i execute it with the packaged mysql client.

[2006-08-14 14:57 UTC] tehjcon at gmail dot com

Actually using queryRow() I get the same error. Sorry about being less specific the "Fatal error:" was from the error handler I'm using but the string "MDB2 Error: Array" is what is returned from $result->getMessage().

Note: The query that its executing has a return of zero rows (at the moment at least) and that seems to be causing the error, the same code works as expected when returning at least 1 row.

MDB2_Error Object
(
[error_message_prefix] =>
[mode] => 1
[level] => 1024
[code] =>
[message] => MDB2 Error: Array
[userinfo] => _doQuery: [Error message: Could not execute statement]
[Last query: SELECT last_modified_time
FROM js_files
WHERE file_path = 'cms/edit.htm']
[Native code: 2013]
[Native message: Lost connection to MySQL server during query]

[2006-08-14 17:43 UTC] phanslem at hotmail dot com

Have tested also here with the same config and i got the "NULL" result.
Same opinion as Lukas... Normally an empty result should not end on a broken connection. Did you try to execute this query directly on the server?

[2006-08-14 18:23 UTC] tehjcon at gmail dot com

Yes the query works fine...

mysql> SELECT last_modified_time FROM js_files WHERE file_path='cms/edit.php';
Empty set (0.00 sec)

Also, the query works fine when returning 1 or more rows; no broken connection.

[2006-08-20 17:08 UTC] tehjcon at gmail dot com

Was not able to recreate the error with the api directly. I made a breif script to test the same query as one failing in MDB2 (verbatim). At this point I think the bug no longer is confined to zero row results. There must be another cause because the script below returns 1 row as expected with mysqli api. However, with mdb2 it returns the dreaded PEAR error class. At this point I'm totally lost as to what might be the cause other than a strange bug in MDB2.

// Test Script

$conn = mysqli_connect('localhost', 'root', '', 'database');

if (!$conn)
{
printf("Connection Failed: %s\n", mysqli_connect_error());
exit;
}

$sql = 'CALL LoadFile(0,\'/header.htm\',\'file_path\')';
$result = mysqli_query($conn, $sql);

while($row = mysqli_fetch_assoc($result))
{
print_r($row);
}

mysqli_free_result($result);
mysqli_close($conn);

The script above returns the expected result set...
Array
(
[file_id] => 6
[parent_id] => 1
[bottom_id] => 14
[top_id] => 15
[filetype] => 1
[filename] => header.htm
[file_path] => /header.htm
[file_size] => 2093
..... etc

[2006-10-01 16:01 UTC] maw01 at student dot uwa dot edu dot au

Hello!

How can I enable 'multi_query' option?

Thanks!

[2006-10-02 04:20 UTC] maw01 at student dot uwa dot edu dot au

If I add

$mdb2->setOption('multi_query', true);

Then do I still need to iterate over all results inside my result class instance using the nextResult() method?

[2006-10-02 12:06 UTC] maw01 at student dot uwa dot edu dot au

hello!

If I call this procedure

$sql = "call pay(".$transaction_id.",".$member_id.",".$dvd_id.", null)";

I think there have a problem if I put null in the parameter! Is it?

How can I solve this problem?

But my procedure can accept null!!!

Error message:

[Mon Oct 02 20:01:53 2006] [error] [client 203.161.68.3] PHP Fatal error: Cannot use object of type MDB2_Error as array in /mnt/data0/jklf/wxyz/public_html/pay.php on line 124, referer: http://address/folder/pay.php