cvs: pear /DB/DB ibase.php

From: Date: Wed, 21 Jan 2004 21:45:07 +0000
Subject: cvs: pear /DB/DB ibase.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-15854@lists.php.net to get a copy of this message
danielc Wed Jan 21 16:45:07 2004 EDT Modified files: /pear/DB/DB ibase.php Log: - REFINE EXECUTE * Allow associative arrays to be passed to execute() and (perhaps speed things) up by using foreach instead of for. Bug 585. * Fix execute() always requiring placeholders. * Do type checking before entering loop to save processing. * Document ability to accept both arrays and scalars. http://cvs.php.net/diff.php/pear/DB/DB/ibase.php?r1=1.33&r2=1.34&ty=u Index: pear/DB/DB/ibase.php diff -u pear/DB/DB/ibase.php:1.33 pear/DB/DB/ibase.php:1.34 --- pear/DB/DB/ibase.php:1.33 Wed Jan 21 13:45:14 2004 +++ pear/DB/DB/ibase.php Wed Jan 21 16:45:07 2004 @@ -16,7 +16,7 @@ // | Author: Sterling Hughes <sterling@php.net> | // +----------------------------------------------------------------------+ // -// $Id: ibase.php,v 1.33 2004/01/21 18:45:14 danielc Exp $ +// $Id: ibase.php,v 1.34 2004/01/21 21:45:07 danielc Exp $ // Bugs: @@ -30,7 +30,7 @@ * extension. * * @package DB - * @version $Id: ibase.php,v 1.33 2004/01/21 18:45:14 danielc Exp $ + * @version $Id: ibase.php,v 1.34 2004/01/21 21:45:07 danielc Exp $ * @category Database * @author Sterling Hughes <sterling@php.net> */ @@ -395,37 +395,43 @@ /** * Executes a DB statement prepared with prepare(). * - * @param $stmt a DB statement resource (returned from prepare()) - * @param $data data to be used in execution of the statement - * - * @return int returns an oci8 result resource for successful - * SELECT queries, DB_OK for other successful queries. A DB error - * code is returned on failure. + * @param resource $stmt a DB statement resource returned from prepare() + * @param mixed $data array, string or numeric data to be used in + * execution of the statement. Quantity of items + * passed must match quantity of placeholders in + * query: meaning 1 for non-array items or the + * quantity of elements in the array. + * @return object a new DB_Result or a DB_Error when fail + * @see DB_ibase::prepare() + * @access public */ - function &execute($stmt, $data = false) + function &execute($stmt, $data = array()) { - $types=&$this->prepare_types[$stmt]; - if (($size = sizeof($types)) != sizeof($data)) { + if (!is_array($data)) { + $data = array($data); + } + + $types =& $this->prepare_types[$stmt]; + if (count($types) != count($data)) { $tmp =& $this->raiseError(DB_ERROR_MISMATCH); return $tmp; } - $pdata[0] = $stmt; - for ($j = 0; $j < $size; $j++) { - $i = $j + 1; - if (is_array($data)) { - $pdata[$i] = &$data[$j]; - } else { - $pdata[$i] = &$data; - } - if ($types[$j] == DB_PARAM_OPAQUE) { - $fp = @fopen($pdata[$i], 'rb'); + + $i = 0; + foreach ($data as $key => $value) { + if ($types[$i] == DB_PARAM_OPAQUE) { + $fp = @fopen($data[$key], 'rb'); if (!$fp) { return $this->raiseError(DB_ERROR_ACCESS_VIOLATION); } - $pdata[$i] = fread($fp, filesize($pdata[$i])); + $data[$key] = fread($fp, filesize($data[$key])); fclose($fp); } + $i++; } + + array_unshift($data, $stmt); + $res = call_user_func_array('ibase_execute', $pdata); if (!$res) { $tmp =& $this->ibaseRaiseError();

« previous php.pear.cvs (#15854) next »