-1

这是我的 SQL 语句:

protected static $_SQLInsert = "INSERT INTO location
(host_id, street, suburb, region, post_code, country, phone, email,
timezone, longitude, latitude, is_main)
VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)";

我准备声明如下:

static::$_PDOSInsert = self::$_PDO->prepare(static::$_SQLInsert);

准备一个包含 12 个值的数组后,我执行以下语句:

static::$_PDOSInsert->execute($array);

然后我收到以下警告:

PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in...

那么,我做错了什么???

编辑:这是数组:

(
    [host_id] => 15
    [street] => Street 15
    [suburb] => Suburb 15
    [region] => Region 15
    [post_code] => Post Code 15
    [country] => AU
    [phone] => 12341234
    [email] => asfd@email.com
    [timezone] => 1
    [longitude] => 123
    [latitude] => 234
    [is_main] => 1
)

谢谢!

4

1 回答 1

2

pdo 对你提供给 execute() 的数组非常挑剔。如果您使用未命名的占位符,例如?,它需要一个数字索引数组,并且它必须从索引 0 开始。

于 2012-06-04T01:11:57.110 回答