PDOStatement :: execute()[pdostatement.execute]:SQLSTATE [HY093]:无效

时间:2014-02-28 19:52:50

标签: php mysql pdo

PDOStatement :: execute()[pdostatement.execute]:SQLSTATE [HY093]:无效的参数编号:绑定变量的数量与令牌的数量不匹配我得到此错误为什么?列名是正确的。

enter image description here

$baslik         = $_POST["makale_basligi"];
$icerik         = trim($_POST["makale_icerigi"]);
$meta_desc      = $_POST["makale_meta_description"];
$id             = $_POST["makale_id"];
$kategori       = $_POST["makale_kategorisi"];
$makale_link    = convertTextToLinkFormat($baslik);

$update_makale  = $db->prepare("UPDATE makale SET "
        . "makale_kategorisi        = :kategori,"
        . "makale_link_baslik       = :link,"
        . "makale_baslik            = :baslik, "
        . "makale_icerik            = :icerik, "
        . "makale_meta_description  = :desc WHERE makale_id = '".$id."' ");
$update_makale->execute(array(':kategori'=>$kategori,':link'=>$makale_link ,':baslik' =>$baslik,':icerik' =>$icerik,':desc' =>$meta_desc));

1 个答案:

答案 0 :(得分:0)

我不认为对$id值进行硬编码并将其与PDO参数混合是一个好主意。 它很容易出错,并且Id在你的表中被定义为int,所以为什么要引用它呢?

将其与其他参数一起放入数组中:

$update_makale  = $db->prepare("UPDATE makale SET "
        . "makale_kategorisi        = :kategori,"
        . "makale_link_baslik       = :link,"
        . "makale_baslik            = :baslik, "
        . "makale_icerik            = :icerik, "
        . "makale_meta_description  = :desc WHERE makale_id = :id");

$update_makale->execute(array(
    ':kategori' => $kategori,
    ':link' => $makale_link,
    ':baslik' => $baslik,
    ':icerik' => $icerik,
    ':desc' => $meta_desc,
    ':id' => $id
));