SQL:查询有效,但出错了吗?

时间:2015-09-11 12:12:16

标签: php mysql pdo

查询有效,但我在尝试查看错误时遇到错误但却无法解决。 所有变量得到"值=' 1' "标记时......

$tuning = SESSION['tuning']));
$garanciq = (!empty($_SESSION['garanciq']));
$avtopilot = (!empty($_SESSION['avtopilot'])); 
$servo = (!empty($_SESSION['servo']));   
$tiptronik = (!empty($_SESSION['tiptronik']));
$servo = (!empty($_SESSION['servo']));
$service = (!empty($_SESSION['service']));
$bord = (!empty($_SESSION['bord']));
$navi = (!empty($_SESSION['navi']));
$volan = (!empty($_SESSION['volan']));  
$zastrahovka = (!empty($_SESSION['zastrahovka']));    

$iInsert= new general();
$iInsert->query("INSERT INTO  other_checkbox 
                 (tuning, garanciq, avtopilot, servo, tiptronik,
                  bord_komp, serviz_knijka, navig_sistema, desen_volan, 
                  zastrahovka) 
                 VALUES " . "(:tuning, :garanciq, avtopilot, :servo, 
                              :tiptronik, :bord, :serviceBook, :navi, 
                              :volan, :zastrahovka)");

$iInsert->bind(':tuning', $tuning);
$iInsert->bind(':garanciq', $garanciq);
$iInsert->bind(':avtopilot', $avtopilot);
$iInsert->bind(':servo', $servo);
$iInsert->bind(':tiptronik', $tiptronik);
$iInsert->bind(':bord', $bord);
$iInsert->bind(':serviceBook', $service);
$iInsert->bind(':navi', $navi);
$iInsert->bind(':volan', $volan);
$iInsert->bind(':zastrahovka', $zastrahovka);
$iInsert->execute();
$iInsert->debugDumpParams(); ->get error, but have Fatal Error !
$insert_other_chek = $iInsert->lastInsertId();->get LastInsertId

我收到此错误

Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens in C:\xampp\htdocs\test\ClassGeneral.php on line 45

Fatal error: Call to undefined method general::debugDumpParams() in C:\xampp\htdocs\test\publicFinish.php on line 165

这是我的班级将军!

class general {

    private $db;
    private $stmt;

    public function __construct() {
        $this->db = new connect();
        $this->db = $this->db->connectDb();
    }
    public function query($sql) {
        $this->stmt = $this->db->prepare($sql);
    }  
    public function execute() {
        return $this->stmt->execute();
    }    
}

4 个答案:

答案 0 :(得分:3)

替换

avtopilot

:avtopilot
查询中的

$iInsert->query("
    INSERT INTO  other_checkbox 
        (tuning, garanciq, avtopilot, servo, tiptronik, bord_komp, serviz_knijka, navig_sistema, desen_volan, zastrahovka) 
    VALUES
        (:tuning, :garanciq, :avtopilot, :servo, :tiptronik, :bord, :serviceBook, :navi, :volan, :zastrahovka)
");

答案 1 :(得分:1)

在您的课程中,您没有binddebugDumpParams

这些功能

答案 2 :(得分:0)

让我给你一个建议。 不要使用来自culttt文章的那个类。

与香草PDO相比,它没有任何好处,但有一些严重的缺点。

$stmt = $pdo->prepare("INSERT INTO  other_checkbox 
             (tuning, garanciq, avtopilot, servo, tiptronik,
              bord_komp, serviz_knijka, navig_sistema, desen_volan, 
              zastrahovka) 
             VALUES (:tuning, :garanciq, :avtopilot, :servo, 
                          :tiptronik, :bord, :serviceBook, :navi, 
                          :volan, :zastrahovka)");

$stmt->execute(array($tuning, $garanciq,$avtopilot,$servo,$tiptronik,
               $bord,$service,$navi,$volan, $zastrahovka));
$insert_other_chek = $stmt->lastInsertId();

是您需要的所有代码。

答案 3 :(得分:-1)

你没有将函数bind()带入类通用