简体   繁体   English

消息为'SQLSTATE [HY093]:未捕获的异常'PDOException':无效的参数号:未定义参数'

[英]Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: parameter was not defined'

I read a lot of similar topics, but i can't understand my mistake. 我读了很多类似的主题,但是我听不懂我的错误。

Problem: 问题:

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

Code: 码:

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 method: PDO_wrap方法:

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

You have a mismatch between class props and your values list 您的类道具和值列表不匹配

$ya_index_data; 

vs

:ya_index_date

I came across the same problem. 我遇到了同样的问题。 PDO requires that the number of entries in an array match the number of of elements in the SQL statement. PDO要求数组中的条目数与SQL语句中的元素数相匹配。 I tried to do the same thing by giving PDO the $_POST array. 我试图通过给PDO $ _POST数组来做同样的事情。 Only after the elements were copied to another array did PDO accept the array. 只有将元素复制到另一个数组后,PDO才接受该数组。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 致命错误:消息中出现“ SQLSTATE [HY093]:无效的参数编号:未定义参数”的未捕获异常“ PDOException” - Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: parameter was not defined' in 消息“ SQLSTATE [HY093]”的异常“ PDOException”:参数号无效 - exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number 注意:带有消息“ SQLSTATE [HY093]:参数号无效:参数未定义”的异常“ PDOException” - Notice: exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: parameter was not defined' 消息为“ SQLSTATE [HY093]:参数号无效”的未捕获异常“ PDOException” - Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number' PHP致命错误:消息为'SQLSTATE [HY093]的未捕获异常'PDOException':无效的参数编号: - PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: PHP PDO SQL错误:带有消息'SQLSTATE [HY093]的未捕获异常'PDOException':参数号无效 - PHP PDO SQL error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number 致命错误:带有消息'SQLSTATE [HY093]的未捕获异常'PDOException':参数号无效:没有参数被绑定 - Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: no parameters were bound 消息“ SQLSTATE [HY093]”的“ PDOException”:无效的参数号: - 'PDOException' with message 'SQLSTATE[HY093]: Invalid parameter number: 绑定参数错误:致命错误:未捕获的 PDOException:SQLSTATE[HY093]:无效的参数号:未定义参数 - Binding parameters error:Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in 致命错误:未捕获的 PDOException:SQLSTATE[HY093]:无效参数号:未定义参数 - Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
相关标签
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM