SQLSTATE: 無效的參數數量:綁定變數的數量與令牌的數量不匹配,位於第102行
P粉386318086
2023-08-17 20:03:40
<p>我收到了SQLSTATE[HY093]錯誤:綁定變數的數量與令牌的數量不匹配,位於comments.php的第102行以下:</p>
<pre class="brush:php;toolbar:false;"><?php
/*** 用於處理文章的類*/
class Comment
{
// 屬性
/*** @var int 資料庫中的文章ID*/
public $id = null;
/*** @var int 文章將要/已經發布的日期*/
public $publicationDate = null;
/*** @var string 文章的完整標題*/
public $title = null;
/*** @var string 文章的HTML內容*/
public $content = null;
/*** @var int 資料庫中的文章ID*/
public $articleid = null;
/*** 使用提供的陣列中的值設定物件的屬性
*
* @param assoc 屬性值*/
public function __construct( $data=array() ) {
if ( isset( $data['id'] ) ) $this->id = (int) $data['id'];
if ( isset( $data['publicationDate'] ) ) $this->publicationDate = (int) $data['publicationDate'];
if ( isset( $data['title'] ) ) $this->title = preg_replace ( "/[^.,-_'"@?!:$ a-zA-Z0-9()]/", "", $data['title'] );
if ( isset( $data['content'] ) ) $this->content = $data['content'];
if ( isset( $data['articleid'] ) ) $this->articleid = (int) $data['articleid'];
}
/*** 使用編輯表單的POST值設定物件的屬性
*
* @param assoc 表單POST值*/
public function storeFormValues( $params ) {
// 儲存所有參數
$this->__construct( $params );
// 解析並儲存發布日期
if ( isset($params['publicationDate']) ) {
$publicationDate = explode ( '-', $params['publicationDate'] );
if ( count($publicationDate) == 3 ) {
list ( $y, $m, $d ) = $publicationDate;
$this->publicationDate = mktime ( 0, 0, 0, $m, $d, $y );
}
}
}
public static function getById( $id ) {
$conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
$sql = "SELECT *, UNIX_TIMESTAMP(publicationDate) AS publicationDate FROM comments WHERE id = :id";
$st = $conn->prepare( $sql );
$st->bindValue( ":id", $id, PDO::PARAM_INT );
$st->execute();
$row = $st->fetch();
$conn = null;
if ( $row ) return new Comment( $row );
}/*** 傳回資料庫中的所有(或一定範圍內的)文章對象
*
* @param int 可選 要傳回的行數(預設為全部)
* @param string 可選 依照哪個欄位對文章進行排序(預設為"publicationDate DESC")
* @return Array|false 一個包含兩個元素的陣列:results => array,文章物件的列表;totalRows => 文章的總數*/
公用靜態函數 getList( $art=1, $order="publicationDate DESC", $numRows=10000 ) {
$conn = 新 PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
$sql = "SELECT SQL_CALC_FOUND_ROWS *, UNIX_TIMESTAMP(publicationDate) AS PublicationDate FROM comments WHERE Articleid = :art
ORDER BY " . mysql_escape_string($order) . " LIMIT :numRows";
$st = $conn->準備( $sql );
$st->bindValue( ":art", $art, PDO::PARAM_INT );
$st->execute();
$列表=陣列();
while ( $row = $st->fetch() ) {
$comments = 新評論( $row );
$列表[] = $評論;
}
}
/*** 將目前的文章物件插入資料庫中,並設定其ID屬性。*/
公共函數插入(){
// 插入文章
$conn = 新 PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
$sql = "INSERT INTO comments (publicationDate, title, content,articledid) VALUES (FROM_UNIXTIME(:publicationDate), :title, :content, :articleid)";
$st = $conn->準備 ( $sql );
$st->bindValue( ":publicationDate", $this->publicationDate, PDO::PARAM_INT );
$st->bindValue( ":title", $this->title, PDO::PARAM_STR );
$st->bindValue( ":content", $this->content, PDO::PARAM_STR );
$st->bindValue( ":articleid", $this->articleid, PDO::PARAM_STR );
$st->execute();
$this->id = $conn->lastInsertId();
$conn = null;
}
/**
* 在資料庫中更新目前的文章物件。*/
公共函數更新(){
// 更新文章
$conn = 新 PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
$sql = "更新註解 SETpublicationDate=FROM_UNIXTIME(:publicationDate), title=:title,summary=:summary,content=:content,articleid=:articleid,imageExtension=:imageExtension WHERE id = :id";
$st = $conn->準備 ( $sql );
$st->bindValue( ":publicationDate", $this->publicationDate, PDO::PARAM_INT );
$st->bindValue( ":title", $this->title, PDO::PARAM_STR );
$st->bindValue( ":content", $this->content, PDO::PARAM_STR );
$st->bindValue( ":articleid", $this->articleid, PDO::PARAM_STR );
$st->bindValue( ":id", $this->id, PDO::PARAM_INT );
$st->execute();
$conn = null;
}
/*** 從資料庫中刪除目前的文章物件。*/
公用函數刪除(){
// 刪除文章
$conn = 新 PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
$st = $conn->prepare("DELETE FROM comments WHERE id = :id LIMIT 1");
$st->bindValue( ":id", $this->id, PDO::PARAM_INT );
$st->execute();
$conn = null;
}
}
?></pre>
<p><br />></p>
您沒有在此處綁定所有的綁定
您宣告了一個名為:numRows的綁定,但您實際上沒有將任何內容綁定到它上面。