【问题标题】:pdo parameter is not bindingpdo 参数未绑定
【发布时间】:2014-09-26 23:29:36
【问题描述】:

我正在尝试将参数绑定到我的查询,它没有绑定某些参数。

发布的数组是

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

【问题讨论】:

  • 你想要UPDATE,而不是INSERT INTO
  • 连接打开后立即添加setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION),如果您还没有这样做的话。它应该表示语法错误。
  • @Fred-ii- 不,我想要INSERT INTO,而setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION) 也没有显示任何内容
  • 如果异常没有显示任何内容,则在打开<?php 标签error_reporting(E_ALL); ini_set('display_errors', 1); 后将错误报告添加到文件顶部,看看它是否产生任何结果;如果你还没有这样做。
  • 顺便问一下parms是什么自定义函数?

标签: php mysql codeigniter debugging pdo


【解决方案1】:

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);

【讨论】:

    猜你喜欢
    • 2017-01-29
    • 2011-08-29
    • 2013-10-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-01-31
    • 2016-06-29
    • 2016-08-18
    相关资源
    最近更新 更多