PHP Pdoexception: "Sqlstate[Hy093]: Invalid Parameter Number"

PHP PDOException: SQLSTATE[HY093]: Invalid parameter number

Try:

$sql = "INSERT INTO persist (user_id, hash, expire)
VALUES (:user_id, :hash, :expire)
ON DUPLICATE KEY UPDATE hash=:hash2";

and

$stm->execute(
array(":user_id" => $user_id,
":hash" => $hash,
":expire" => $future,
":hash2" => $hash)
);

Excerpt from the documentation (http://php.net/manual/en/pdo.prepare.php):

You must include a unique parameter marker for each value you wish to pass in to the statement when you call PDOStatement::execute(). You cannot use a named parameter marker of the same name twice in a prepared statement. You cannot bind multiple values to a single named parameter in, for example, the IN() clause of an SQL statement.

Binding parameters error:Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in

Hyphen "-" is a reserved character for pdo sql parser, so it must not be used in placeholder names, hence address-town and address-country are invalid names and cause the mentioned error.

Use alphanumeric characters and underscore only.

a-zA-Z0-9_

Reserved characters:

:?"'-/

See the docs https://github.com/php/php-src/blob/master/ext/pdo/pdo_sql_parser.re

PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens on line 27

In your SQL you are using a parameter in the where clause, ":product_id", but it seems you forgot to bind it. Add the bind statement.

php error: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined

You don't need to surround your parameter name with '. Remove ' before and after :password. Change

$query = "INSERT INTO " . $this->table_name . "
(first_name,last_name,phone,password_hash)
values (:first_name,:last_name,:phone,':password')
";

to

 $query = "INSERT INTO " . $this->table_name . "
(first_name,last_name,phone,password_hash)
values (:first_name,:last_name,:phone,:password)
";

Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined in (xxx) PDOStatement->execute()

your statement has :used_by

   $update_statement = $this->pdo->prepare("UPDATE `private_key` SET `used` = :used, `user_id` = :used_by WHERE `key` = :keyText");

But your params is providing :user

   $update_statement->bindParam(':user', $id, PDO::PARAM_INT);


Related Topics



Leave a reply



Submit