我正在将我的项目切换到 PDO,但我遇到了以下代码的问题。它不会抛出错误,但也不会插入数据库。我一直在阅读 PDO 并研究了DebugdumpParams()
. 我添加$result->debugDumpParams()
了,页面没有加载。
我需要使用BindParam()
after prepare()
, beforeexecute()
才能调试吗?
public function CustomerInsert($name, $street1, $street2, $city, $state, $zip, $phone_area, $phone, $email, $notes, $leadtype, $rating, $newsletter, $frequency)
{
$q = "INSERT INTO customers VALUES('', :name , :street1 , :street2 , :city , :state , :zip , :phone_area , :phone , :email , :notes , :newsletter , :leadtype , :frequency )";
try{
$result = $this->connection->prepare($q);
$result->execute(array(':name'=>$name, ':street1'=>$street1, ':street2'=>$street2,
':city'=>$city, ':state'=>$state, ':zip'=>$zip, ':phone_area'=>$phone_area,
':phone'=>$phone, ':email'=>$email, ':notes'=>$notes, ':newsletter'=>$newsletter,
':leadtype'=>$leadtype, ':frequency'=>$frequency));
}
catch (PDOException $e)
{
throw new Exception('Connection failed: ' . $e->getMessage());
}