我已经通过PHP和PDO创建了SQLite3数据库
插入记录和删除记录可以正常工作,但UPDATE记录不能
public function update_All($mStore_Order_DataClass) {
try
{
$sql = "UPDATE Orders "
. "SET x_Name = :x_Name, "
. "x_PhoneNumber1 = :x_PhoneNumber1, "
. "x_PhoneNumber2 = :x_PhoneNumber2, "
. "x_Address1 = :x_Address1, "
. "x_Date = :x_Date, "
. "x_Time = :x_Time, "
. "x_Status = :x_Status, "
. "x_M2 = :x_M2, "
. "x_M3 = :x_M3, "
. "x_Barcode = :Barcode, "
. "x_Price = :x_Price, "
. "x_Discount = :x_Discount, "
. "x_Number = :x_Number "
. "WHERE x_ID = :x_ID ";
$stmt = $this->pdo->prepare($sql);
$stmt->bindValue(':x_ID' , $mStore_Order_DataClass->getx_ID() );
$stmt->bindValue(':x_Name' , $mStore_Order_DataClass->getx_Name() );
$stmt->bindValue(':x_PhoneNumber1', $mStore_Order_DataClass->getx_PhoneNumber1());
$stmt->bindValue(':x_PhoneNumber2', $mStore_Order_DataClass->getx_PhoneNumber2());
$stmt->bindValue(':x_Address1' , $mStore_Order_DataClass->getx_Address1() );
$stmt->bindValue(':x_Date' , $mStore_Order_DataClass->getx_Date() );
$stmt->bindValue(':x_Time' , $mStore_Order_DataClass->getx_Time() );
$stmt->bindValue(':x_Status' , $mStore_Order_DataClass->getx_Status() );
$stmt->bindValue(':x_M2' , $mStore_Order_DataClass->getx_M2() );
$stmt->bindValue(':x_M3' , $mStore_Order_DataClass->getx_M3() );
$stmt->bindValue(':x_Barcode' , $mStore_Order_DataClass->getx_Barcode() );
$stmt->bindValue(':x_Price' , $mStore_Order_DataClass->getx_Price() );
$stmt->bindValue(':x_Discount' , $mStore_Order_DataClass->getx_Discount() );
$stmt->bindValue(':x_Number' , $mStore_Order_DataClass->getx_Number() );
$stmt->execute();
$mrowCount = $stmt->rowCount();
echo "\nA :\n{$mrowCount}\n";
return TRUE;
}
catch (\PDOException $e)
{
return FALSE;
}
}
似乎没有匹配项,因此没有更新原因$mrowCount
为0
我看到有一个匹配的 SQLITE数据库浏览器
我还将断点放在代码中,下面您可以从netbeans IDE的变量窗口中看到 $ sql :
“ UPDATE命令SET x_Name =:x_Name,x_PhoneNumber1 =:x_PhoneNumber1, x_PhoneNumber2 =:x_PhoneNumber2,x_Address1 =:x_Address1,x_Date = :x_Date,x_Time =:x_Time,x_Status =:x_Status,x_M2 =:x_M2,x_M3 = :x_M3,x_Barcode =:条形码,x_Price =:x_Price,x_Discount = :x_Discount,x_Number =:x_Number WHERE x_ID =:x_ID“
因此您可以看到没有更新的情况下ID-2匹配
BTW, 没有错误,并返回TRUE
这是怎么回事?
答案 0 :(得分:0)
我缩小了代码范围,最后发现如下问题:
x_Barcode =:条形码
必须如下:
x_Barcode =: x _ 条形码
这确实是一个无声的问题,因为没有错误,并且函数返回true