PDO插入查询不插入数据

时间:2014-10-01 20:16:51

标签: php mysql codeigniter pdo insert

我正在尝试使用PDO插入一些数据,如下所示

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


if ($statement->execute()) {
        echo "executed"; exit;
        return $this->db->conn_id->lastInsertId();
    } else {
        echo "not executed"; exit;
    }

它始终显示我" Not Executed",但是当我手动运行查询时,它工作正常

1 个答案:

答案 0 :(得分:0)

问题是你要混合bind和字符串。

绑定

$parent_id
$cat_description

你打错了我的朋友。清理你的代码。

   $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";
相关问题