2014-09-26 99 views
1

我想绑定一个参数到我的查询,它不绑定一些参数。pdo参数不具约束力

发布阵列是

Array 
(
    [action] => add_category 
    [fk_user_account_type_id] => Array 
     (
      [0] => 1 
      [1] => 2 
      [2] => 5 
      [3] => 6 
      [4] => 7 
      [5] => 8 
      [6] => 9 
     ) 

    [cat_name] => Special Deals 
    [parent_cat] => 0 
    [cat_status] => Active 
    [page_content] => 

this is test 
) 

$cat_name = $postArray['cat_name']; 
$cat_status = $postArray['cat_status']; 
$parent_id = $postArray['parent_cat']; 
$cat_description = $postArray['page_content']; 

$sql = "INSERT INTO tbl_category SET `category_title` = :cat_name , `category_alias` = :category_alias , `category_status`= :cat_status, `category_parent_id` = :parent_id, " 
       . "category_description = :cat_description"; 
     $statement = $this->db->conn_id->prepare($sql); 
     $statement->bindParam(':cat_name', $cat_name, PDO::PARAM_STR); 
     $statement->bindParam(':cat_status', $cat_status, PDO::PARAM_STR); 
     $statement->bindParam(':category_alias', $category_alias, PDO::PARAM_STR); 
     $statement->bindParam(':parent_id', $parent_id, PDO::PARAM_INT); 
     $statement->bindParam(':cat_description',$cat_description, PDO::PARAM_STR); 

,当我做

echo $this->parms($sql,$postArray); exit // for debugging; 

它显示我像

INSERT INTO tbl_category SET `category_title` = 'Special Deals' , `category_alias` = 'special_deals' , `category_status`= 'Active', `category_parent_id` = :parent_id, category_description = :cat_description 
+0

你想'UPD​​ATE',不'INSERT INTO' – 2014-09-26 23:32:01

+0

添加'的setAttribute(PDO :: ATTR_ERRMODE,PDO :: ERRMODE_EXCEPTION)连接后'权被打开,如果你没有这样做。它应该表明语法错误。 – 2014-09-26 23:33:49

+0

@ Fred-ii-不,我想要'INSERT INTO'和'setAttribute(PDO :: ATTR_ERRMODE,PDO :: ERRMODE_EXCEPTION)'也没有向我展示任何东西 – baig772 2014-09-26 23:36:26

回答

0

BindParam经过参考查询,以便它需要一个值,你有没有,用bindValue代替它。

$statement->bindValue(':cat_name', $cat_name, PDO::PARAM_STR); 
    $statement->bindValue(':cat_status', $cat_status, PDO::PARAM_STR); 
    $statement->bindValue(':category_alias', $category_alias, PDO::PARAM_STR); 
    $statement->bindValue(':parent_id', $parent_id, PDO::PARAM_INT); 
    $statement->bindValue(':cat_description',$cat_description, PDO::PARAM_STR);