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

时间:2012-04-09 08:35:44

标签: php pdo

为什么这个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();

2 个答案:

答案 0 :(得分:14)

因为您在创建语句之前尝试将bind参数添加到语句中。首先是prepare(),然后是bind

答案 1 :(得分: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();