How do I prevent Zend from trying to bind my MySQL values?
I have a query like:
INSERT IGNORE INTO my_table SET `data` = '{\"m\":50}'
Granted the JSON data is much larger in my real query, I always get the
error:
Zend_Db_Statement_Exception: Invalid bind-variable name ':50'
This is when I do $connection->query( $sql );
In the past I've solved this by using single quotes rather than double
quotes around my values, but for some reason it's not working now. What am
I missing?
EDIT
On top of the accepted answer, here is the code I used to make sure I can
still pass new Zend_Db_Expr("NOW()") to my function, but have something
like the JSON data prepared properly.
foreach ( $params as $key => $value ) {
// Can't use ? for anything that requires an expression, such as NOW()
if ( $value instanceof Zend_Db_Expr ) {
$db_keys[] = $connection->quoteInto( "`{$key}` = ?", $value );
}
else {
$db_values[] = $value;
$db_keys[] = "`{$key}` = ?";
}
} // foreach params
$sql = "INSERT IGNORE INTO {$table} SET " . implode( ', ', $db_keys );
$result = $connection->query( $sql, $db_values );
No comments:
Post a Comment