PEAR is archived and read-only

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

Home » Database » MDB2 » Bug #8720

executeMultiple fails for empty $values array

Details

Submitted2006-09-17 10:00 UTC
Fromjo at durchholz dot org
StatusBogus
PackageMDB2
PHP Version4.3.4
OSIrrelevant
Roadmaps(Not assigned)

Comments

[2006-09-17 10:00 UTC] jo at durchholz dot org

Description:
------------
If executeMultiple is given a $values parameter of the form
array (
array ()
)
MDB2_Statement_Common::bindValueArray will call
array_fill (0, 0, NULL)
which in turn will issue a warning and return FALSE.

(I consider this a bug in array_fill, which should simply return an empty array, but this won't fix all those old(ish) PHP installations.)

This situation can occur only if executeMultiple is used to handle queries that don't have parameters. (I do this because I have a DB layer on top of MDB2, which uses executeMultiple for all queries for simplicity.)

Test script:
---------------
# Warning: I haven't tested this stripped-down version.

$prepared_query =
$_db->prepare (
'TRUNCATE TABLE t',
NULL,
MDB2_PREPARE_MANIP
);
$_db->extended->executeMultiple (
$prepared_query,
array (array ())
);

# 'TRUNCATE TABLE t' should be executed once, so the
# $values parameter must have one entry.
# 'TRUNCATE TABLE t' does not have parameter, so that
# entry in $values must be an empty array.
# That's the background behind the array (array ())
# construct above.

###########################################################

Original code:

-- snip --
function bindValueArray(&$values, $types = null)
{
$types = is_array($types) ? array_values($types) : array_fill(0, count($values), null);
-- snip --

Bug fix:
-- snip --
function bindValueArray(&$values, $types = null)
{
$types =
is_array($types) ? array_values($types)
: count($values) == 0 ? array ()
: array_fill(0, count($values), null);
-- snip --

Expected result:
----------------
No warnings.

Actual result:
--------------
Issues warning (I have my own error handler, so wording and formatting deviate from normal PHP output):

pear\MDB2.php, line 3886:
array_fill(): Number of elements must be positive

[2006-09-17 21:25 UTC] jo at durchholz dot org

This says
string(17) "@package_version@"
Not very helpful, I admit...

... BUT I have kept the downloaded files in a properly version-numbered download directory, and there it says "2.2.0".
Sorry if this problem is already fixed in 2.2.2. I will upgrade to 2.2.2 and report again tomorrow or so.

[2006-09-17 21:27 UTC] jo at durchholz dot org

(Corrected the summary - somehow it got taken from my previous bug report.)

[2006-09-18 20:49 UTC] jo at durchholz dot org

> The given code has not been changed in a while:

Hm... you're right. And checking the execution flow with the debugger showed that it doesn't happen anymore, though I can't say whether that's because I upgraded to 2.2.2 or not.

This seems to be irreproducible in 2.2.2, so I closed the bug.