我正在使用Zend_Db_Adapter_Abstract
来处理DB数据,当我对没有权限向DB中插入数据的DB用户使用其方法insert
时,代码500出现错误。如果此方法没有引发任何异常,我会处理这种情况吗?
方法如下:
public function insert($table, array $bind)
{
// extract and quote col names from the array keys
$cols = array();
$vals = array();
$i = 0;
foreach ($bind as $col => $val) {
$cols[] = $this->quoteIdentifier($col, true);
if ($val instanceof Zend_Db_Expr) {
$vals[] = $val->__toString();
unset($bind[$col]);
} else {
if ($this->supportsParameters('positional')) {
$vals[] = '?';
} else {
if ($this->supportsParameters('named')) {
unset($bind[$col]);
$bind[':col'.$i] = $val;
$vals[] = ':col'.$i;
$i++;
} else {
/** @see Zend_Db_Adapter_Exception */
require_once 'Zend/Db/Adapter/Exception.php';
throw new Zend_Db_Adapter_Exception(get_class($this) ." doesn't support positional or named binding");
}
}
}
}
// build the statement
$sql = "INSERT INTO "
. $this->quoteIdentifier($table, true)
. ' (' . implode(', ', $cols) . ') '
. 'VALUES (' . implode(', ', $vals) . ')';
// execute the statement and return the number of affected rows
if ($this->supportsParameters('positional')) {
$bind = array_values($bind);
}
$stmt = $this->query($sql, $bind);
$result = $stmt->rowCount();
return $result;
}