SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens on line 102
You didn't bind all your bindings here
$sql = "UNIX_TIMESTAMP(publicationDate) AS publicationDate
FROM comments WHERE articleid = :art
ORDER BY some LIMIT :numRows";
$st = $conn->prepare( $sql );
$st->bindValue( ":art", $art, PDO::PARAM_INT );
You've declared a binding called :numRows but you never actually bind anything to it.
SQLSTATE[HY093]: number of bound variables does not match number of tokens in
Only bind values to the prepared statement where you have a placeholder.
$this->query('INSERT INTO apply_later(id, title, body, link, user_id, user_name)
SELECT id, title, body, link, user_id, user_name FROM shares WHERE id = :id');
// only 1 placeholder-------------------------------------------^^^
Remove these lines because they are not represented in the prepared statement:$this->bind(':title', 'title');
$this->bind(':body', 'body');
$this->bind(':link', 'link');
$this->bind(':user_id', 1);
$this->bind(':user_name', 'user_name');
Just bind :id
:
$this->bind(':id', $_POST['applylater_id']);
Warning: PDOStatement::execute(): SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens
The problem is your data, more specifically your first line:
SBT Interview End Date,Week End Date,YYYY Mm,SBT Case ID,SBT Response ID,SBT Agent,SBT Channel Name,SBT Msg Created,SBT Close Date,SBT Contact Count,SBT Queue Nm,SBT Vendor Name,SBT Location Name,SBT Message Age,SBT Q1 (Email overall score),SBT Q2 (Was your issue resovled?),SBT Q201(NPS),SBT Q200(Ease of contact Customer Care),SBT Q186 (Verbatim),FCR,FCR Count
One field contains a question mark:
SBT Q2 (Was your issue resovled?)
This is interpreted as another placeholder in the query, hence your array doesn't match.
You can solve this by removing question marks from the keys:
$keys[$key] = str_replace("?", "", $value);
PHP PDO update a joined table
There are 2 placeholders here, :genre
and :album_id
$genre_update = 'UPDATE genres SET genre=:genre WHERE albums.genre_id=:album_id';
But you only supplied one to your execute statement.
$genre_statement->execute([':genre' => $genre]);
You simply need to pass all the parameters.
$genre_statement->execute([':genre' => $genre, ':album_id' => $album_id]);
Same goes for your artist statements.
Warning: PDOStatement::bindValue(): SQLSTATE[HY093]: Invalid parameter number: Columns/Parameters are 1-based
$i = 0
And
Warning: PDOStatement::bindValue(): SQLSTATE[HY093]: Invalid parameter number: Columns/Parameters are 1-based
Compare those two things, you will notice that your $i
has to start at 1, not 0.
This can also be confirmed from the PHP Manual
parameter
Parameter identifier. For a prepared statement using named placeholders, this will be a parameter name of the form :name. For a prepared statement using question mark placeholders, this will be the 1-indexed position of the parameter.
PDOException: Invalid parameter number with message 'SQLSTATE[HY093]: Columns/Parameters are 1-based'
Marc B's answer was close, but in the end, the fix was actually more simple than I'd thought.
I was passing the $m_param_key
through one too many foreach loops and needed to keep it on the outside loop.
Here's the resolved code:
// bind the parameters
if (sizeof($m_arr_query_parameters) > 0)
{
foreach ($m_arr_query_parameters as $m_param_key => $m_param_values)
{
foreach($m_param_values as $m_param_value)
{
$this->c_obj_stmt->bindParam($m_param_key, $m_param_value);
}
}
}
// execute the query
$m_execute_result = $this->c_obj_stmt->execute();
$this->c_arr_database_connection_messages['execute-OK'] = $m_execute_result;
$m_database_query_execute_error = false;
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.
Related Topics
Sqlsrv_Num_Rows Not Returning Any Value
PHP Exec $Path Variable Missing Elements
Custom User Authentication Base on the Response of an API Call
What's the Best Way to Pass a PHP Variable to JavaScript
Will Copy-On-Write Prevent Data Duplication on Arrays
How to Create Codeigniter Batch Insert Array
Check Whether the String Is a Unix Timestamp
MySQL No Connection Could Be Made Because the Target MAChine Actively Refused It
Hide Shipping Methods for Specific Shipping Class in Woocommerce
Preg_Match(); - Unknown Modifier '+'
Setting Value of a HTML Form Textarea
How to Connect to Mssql Using Pdo Through PHP and Linux
How to Fetch All in Assoc Array from a Prepared Statement