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 PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
In updateRequest()
, you need to bind the :R_id
parameter:
$stmt->bindParam(":R_id", $this->R_id);
SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens COUNT IS CORRECT
Each parameter needs to be a separate element in the array passed to $stmt->execute()
, it shouldn't be a single comma-separated string.
<?php
$DSN = "mysql:host=$HOST;dbname=$DBName;charset=utf8";
$Options = array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, PDO::ATTR_EMULATE_PREPARES => false,);
try{$pdo = new PDO($DSN, $USER, $PASSWORD, $Options);}
catch (PDOException $e)
{
$LogData = "\n".date('Y-m-d H:i').' '.$_SESSION[PageName].' '.$e->getMessage().' '.(int)$e->getCode();
error_log($LogData, 3, "error.log");
exit('<h2 style="width:90%; border:2px solid #FF0000; padding:15px;">Server Connect Error! [1]</h2>');
}
$FCount = 0;
$VCount = 0;
$PCount = 0;
$PrepString = str_repeat("?, ", count($RateVars));
$FieldString = implode(',', array_keys($RateVars));
$PrepString .= '?';
$FieldString .= ', Server';
$ValArray = array_values($RateVars);
$ValArray[] = $Node;
$sql = 'INSERT INTO Archive ('.$FieldString.') VALUES ('.$PrepString.')';
$stmt = $pdo->prepare($sql);
try {
$stmt->execute($ValArray);
} catch (PDOException $e)
{
$ErrorMsg = "DataBase Error in Save to Archive"; $Status=1;
$LogData = "\n".date('Y-m-d H:i').' '.$_SESSION[PageName].' '.$ErrorMsg.' '.$e->getMessage().' '.(int)$e->getCode();
$LogData .= "\n".'F: '.$FCount.' V: '.$VCount.' P: '.$PCount;
$LogData .= "\n".'F: '.$FieldString."\n".' V: '.implode(',', $ValArray)."\n".' P: '.$PrepString."\n".$sql;
error_log($LogData, 3, "error.log");
}
?>
PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
You only need to pass an array to the execute method. So your updated code would look like this:
$sql = 'INSERT INTO `' . $table_name . '` '
. '(`day`, `campaign_name`, `campaign_id`, `views`, `CPM`, `cost`, `currency`, `cost_EUR`) VALUES '
. '(:day, :campaign_name, :campaign_id, :views, :CPM, :cost, :currency, :cost_EUR)';
$sth = $this->_dbi->prepare($sql);
$sth->execute(array(
':day' => $day,
':campaign_name' => $campaignName,
':campaign_id' => $campaignID,
':views' => $views,
':CPM' => $cpm,
':cost' => $cost_EUR,
':currency' => 'EUR',
':cost_EUR' => $cost_EUR
));
Read more here: http://php.net/manual/en/pdostatement.execute.php
PDOStatement::execute — Executes a prepared statement
Usage: public bool PDOStatement::execute ([ array $input_parameters ] )
Here is the example from the documentation:
<?php
/* Execute a prepared statement by passing an array of insert values */
$calories = 150;
$colour = 'red';
$sth = $dbh->prepare('SELECT name, colour, calories
FROM fruit
WHERE calories < :calories AND colour = :colour');
$sth->execute(array(':calories' => $calories, ':colour' => $colour));
SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens - help needed
It took me a while to find, but I believe that PDO::prepare passes the named parameters through a regular expression [:][a-zA-Z0-9_]+
. https://github.com/php/php-src/blob/master/ext/pdo/pdo_sql_parser.re#L48. Your diacritic characters are being clobbered.
The only alternative that I know about it to use unnamed placeholders instead - ?
. Something like:
$sql = sprintf(
"INSERT INTO %s (%s) values (%s)",
"Diak",
implode(", ", array_keys($new_user)),
implode(', ', array_fill(0, sizeof($new_user), '?'))
);
Which will produce:
INSERT INTO Diák (oktatási_id, vezeték_név, kereszt_név, évfolyam, születési_dátum, város, utca, házszám, irányítószám, szak, kar) values (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)
You'll then have to change your execute method as follows:
$statement->execute(array_values($new_user));
Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
You forgot the parameter after COMPANY_NAME,
$query = "INSERT INTO client SET CLIENT_UNUM=?, USERNAME=?, USERPASS=?,
USER_FNAME=?, USER_LNAME=?, USER_BDATE=?, USER_PHOTOPATH=?, COMPANY_NAME=?,
STATUS=?, USER_MOBILENUM=?";
SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens'
Your Query
$select = "INSERT INTO registro (nome, usuario, email, senha, cpf, rg)
VALUES (:nome, :usuario, email, :senha, :cpf, :rg)";
After change Missing : in email
$select = "INSERT INTO registro (nome, usuario, email, senha, cpf, rg)
VALUES (:nome, :usuario, :email, :senha, :cpf, :rg)";
Related Topics
Laravel: Validate an Integer Field That Needs to Be Greater Than Another
Executing a Shell Script from a PHP Script
How to Concatenate Multiple Ternary Operator in PHP
Preg_Match(); - Unknown Modifier '+'
How to Detect an Incoming Request (With PHP Script) from a Cname Subdomain
Passing Data to Buildform() in Symfony 2.8, 3.0 and Above
Does PHP's Filter_Var Filter_Validate_Email Actually Work
File_Get_Contents() Give Me 403 Forbidden
PHP Regex - Valid Float Number
What Is a Unix Timestamp and Why Use It
Iterating Over a Complex Associative Array in PHP
How to Fetch All in Assoc Array from a Prepared Statement
Convert Ascii to Utf-8 Encoding
Passing PHP Variable from Controller to JavaScript Function in the Head of a View
Turn Off Warnings and Errors on PHP and MySQL
How to Setup Table Prefix in Symfony2
Sending Images from Canvas Elements Using Ajax and PHP $_Files