3

为什么这个 PHP PDO 片段不起作用?

$DBH = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);  
$STH->bindParam(':fftb', $fftb);  
$STH->bindParam(':st', $st);  
$STH->bindParam(':la', $la);
$STH->bindParam(':cf', $cf);  
$STH->bindParam(':total', $total);  
$STH = $DBH->prepare("INSERT INTO orders (fftb, st, la, cf, total) VALUES (:fftb, :st, :la, :cf, :total)"); 
$STH->execute();
4

2 回答 2

14

因为您试图bind在创建语句之前将参数传递给语句。首先prepare(),然后bind

于 2012-04-09T08:40:48.150 回答
0

检查下面的更正代码:

    $DBH = new PDO("mysql:host=$host;dbname=$dbname", $user, $pass);  
$STH = $DBH->prepare("INSERT INTO orders (fftb, st, la, cf, total) VALUES (:fftb, :st, :la, :cf, :total)"); 
$STH->bindParam(':fftb', $fftb);  
$STH->bindParam(':st', $st);  
$STH->bindParam(':la', $la);
$STH->bindParam(':cf', $cf);  
$STH->bindParam(':total', $total);

$STH->execute();
于 2016-09-12T06:33:58.603 回答