本文介绍了pdo参数不绑定的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图绑定一个参数到我的查询,它不绑定一些参数。
I am trying to bind a param to my query, it is not binding some parameters.
发布的数组是
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
推荐答案
BindParam
通过引用传递,所以它需要一个值,你没有,替换为 bindValue
。
BindParam
passes by reference so it needs a value and you have none,replace it with 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);
这篇关于pdo参数不绑定的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!