cvs: pear /MDB2/MDB2 Extended.php

From: Date: Fri, 18 Aug 2006 21:53:44 +0000
Subject: cvs: pear /MDB2/MDB2 Extended.php
Groups: php.pear.cvs 
Request: Send a blank email to pear-cvs+get-41779@lists.php.net to get a copy of this message
lsmith Fri Aug 18 21:53:44 2006 UTC Modified files: /pear/MDB2/MDB2 Extended.php Log: - added execParam() - code tweaks for get*() methods http://cvs.php.net/viewvc.cgi/pear/MDB2/MDB2/Extended.php?r1=1.51&r2=1.52&diff_format=u Index: pear/MDB2/MDB2/Extended.php diff -u pear/MDB2/MDB2/Extended.php:1.51 pear/MDB2/MDB2/Extended.php:1.52 --- pear/MDB2/MDB2/Extended.php:1.51 Sat Jul 15 13:07:13 2006 +++ pear/MDB2/MDB2/Extended.php Fri Aug 18 21:53:43 2006 @@ -42,7 +42,7 @@ // | Author: Lukas Smith <smith@pooteeweet.org> | // +----------------------------------------------------------------------+ // -// $Id: Extended.php,v 1.51 2006/07/15 13:07:13 lsmith Exp $ +// $Id: Extended.php,v 1.52 2006/08/18 21:53:43 lsmith Exp $ /** * @package MDB2 @@ -275,6 +275,46 @@ } // }}} + // {{{ execParam() + + /** + * Execute a parameterized DML statement. + * + * @param string the SQL query + * @param array if supplied, prepare/execute will be used + * with this array as execute parameters + * @param array that contains the types of the values defined in $params + * + * @return int|MDB2_Error affected rows on success, a MDB2 error on failure + * @access public + */ + function execParam($query, $params = array(), $param_types = null) + { + $db =& $this->getDBInstance(); + if (PEAR::isError($db)) { + return $db; + } + + settype($params, 'array'); + if (empty($params)) { + return $db->exec($query); + } + + $stmt = $db->prepare($query, $param_types, MDB2_PREPARE_MANIP); + if (PEAR::isError($stmt)) { + return $stmt; + } + + $result = $stmt->execute($params); + if (PEAR::isError($result)) { + return $result; + } + + $stmt->free(); + return $result; + } + // }}} + // {{{ getOne() /** @@ -301,7 +341,7 @@ settype($params, 'array'); settype($type, 'array'); - if (count($params) == 0) { + if (empty($params)) { return $db->queryOne($query, $type, $colnum); } @@ -310,8 +350,7 @@ return $stmt; } - $stmt->bindValueArray($params); - $result = $stmt->execute(); + $result = $stmt->execute($params); if (!MDB2::isResultCommon($result)) { return $result; } @@ -348,7 +387,7 @@ } settype($params, 'array'); - if (count($params) == 0) { + if (empty($params)) { return $db->queryRow($query, $types, $fetchmode); } @@ -357,8 +396,7 @@ return $stmt; } - $stmt->bindValueArray($params); - $result = $stmt->execute(); + $result = $stmt->execute($params); if (!MDB2::isResultCommon($result)) { return $result; } @@ -396,7 +434,7 @@ settype($params, 'array'); settype($type, 'array'); - if (count($params) == 0) { + if (empty($params)) { return $db->queryCol($query, $type, $colnum); } @@ -405,8 +443,7 @@ return $stmt; } - $stmt->bindValueArray($params); - $result = $stmt->execute(); + $result = $stmt->execute($params); if (!MDB2::isResultCommon($result)) { return $result; } @@ -452,7 +489,7 @@ } settype($params, 'array'); - if (count($params) == 0) { + if (empty($params)) { return $db->queryAll($query, $types, $fetchmode, $rekey, $force_array, $group); } @@ -461,8 +498,7 @@ return $stmt; } - $stmt->bindValueArray($params); - $result = $stmt->execute(); + $result = $stmt->execute($params); if (!MDB2::isResultCommon($result)) { return $result; } @@ -554,7 +590,7 @@ } settype($params, 'array'); - if (count($params) == 0) { + if (empty($params)) { return $db->queryAll($query, $types, $fetchmode, true, $force_array, $group); } @@ -563,8 +599,7 @@ return $stmt; } - $stmt->bindValueArray($params); - $result = $stmt->execute(); + $result = $stmt->execute($params); if (!MDB2::isResultCommon($result)) { return $result; } @@ -596,8 +631,7 @@ function executeMultiple(&$stmt, $params = null) { for ($i = 0, $j = count($params); $i < $j; $i++) { - $stmt->bindValueArray($params[$i]); - $result = $stmt->execute(); + $result = $stmt->execute($params[$i]); if (PEAR::isError($result)) { return $result; }

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