簡體   English   中英

PDO插入查詢未插入數據

[英]PDO insert query not inserting data

我正在嘗試使用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;
    }

它總是顯示“未執行”,但是當我手動運行查詢時,它可以正常運行

問題是您正在混合綁定和字符串。

綁定

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM