【发布时间】:2018-05-12 11:50:33
【问题描述】:
我正在尝试编写一些控制器来使用 PDO 执行一些 CRUD,并且遇到了这个问题,即什么都没有发生并且不会抛出。我很确定我绑定正确,但是在转储后,我看不到任何问题并且表格没有更新。
有人可以看看吗?
public function update($query, $array)
{
try
{
$stm = $this->conn->prepare($query);
foreach($array AS $key=>$value)
{
if(gettype($value) == "integer")
{
$stm->bindParam($key,$value,PDO::PARAM_INT);
}
if(gettype($value) == "string")
{
$stm->bindParam($key,$value,PDO::PARAM_STR);
}
}
$stm->execute();
return ($stm->rowCount()<=0) ? FALSE : $stm->rowCount();
}
catch(Exception $e)
{
echo 'Error with the query on line: ' . __LINE__ . ' in file: ' . __FILE__;
}
}
$test = new SQL('127.0.0.1', 'test', '*************', 'mike_test');
$pull = $test->update('UPDATE names SET name=:name WHERE id=:id;',[':name'=>'James',':id'=>2]);
【问题讨论】:
标签: php sql pdo sql-update