-1

我阅读了很多类似的主题,但我无法理解我的错误。

问题:

Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: parameter was not defined' in I:\home\lm.ru\www\classes\db.class.php:39 Stack trace: #0 I:\home\lm.ru\www\classes\db.class.php(39): PDOStatement->execute(Array) #1 I:\home\lm.ru\www\classes\page.class.php(34):

代码:

class Page
{
    public $id = "";
    public $link = ""; //+
    public $links_count = 0;//+
    public $places_count = 0;
    public $external_links = 0; //+
    public $context = 0;
    public $has_text = 0;
    public $text = "";
    public $ya_index = 0;
    public $ya_index_data = 0;
    public $google_pr = 0;
    public $google_pr_date = 0;
    public $level = 0; // 0 - main, 1 - 2 level... +
    public $title = ""; // +
    public $is_active = 1;
    public $deleted = 0;
    public $site_id = 0; //+

    function Add($data)
    {
        foreach($data as $key => $value)
        {
            $this->$key = $value;
        }

        print_r((array)$this);

        PDO_wrap::Change("INSERT INTO pages (id, link, links_count, places_count, external_links, context, has_text, text, ya_index, ya_index_date, google_pr, google_pr_date, level, title, is_active, deleted, site_id) VALUES(:id, :link, :links_count, :places_count, :external_links, :context, :has_text, :text, :ya_index, :ya_index_date, :google_pr, :google_pr_date, :level, :title, :is_active, :deleted, :site_id)", (array)$this);

        $this->id = PDO_wrap::LastInsertId();
    }

}

PDO_wrap 方法:

public static function Change($query, $params = array())
    {
        $sql = self::$pdo->prepare($query);
        $sql->execute($params);
        return $sql->rowCount();
    }
4

2 回答 2

6

你的类道具和你的价值观列表不匹配

$ya_index_data; 

对比

:ya_index_date
于 2013-03-24T15:05:26.683 回答
0

我遇到了同样的问题。PDO 要求数组中的条目数与 SQL 语句中的元素数相匹配。我试图通过为 PDO 提供 $_POST 数组来做同样的事情。只有在元素被复制到另一个数组之后,PDO 才接受该数组。

于 2016-08-25T20:50:47.690 回答