For an SQL query involving multiple tables, how do I construct such PDO statement like this?
Because this doesn't work:
$stmt = $pdo -> prepare("UPDATE category, product
SET product.category_id = category.id,
product.xxx = :product.xxx,
category.yyy = :category.yyy
WHERE product.category_slug = category.slug
AND product.aaa = :product.aaa"
);
$stmt->execute(array(
'product.xxx' => '',
'category.yyy' => '',
'product.aaa' => ''
));
Which gives these errors:
Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[HY093]:
Invalid parameter number: parameter was not defined'
PDOException: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined
How do I make this work? PDO doesn't seem to allow period dots in marked parameters? I guess I'm doomed with underscores?
Here are the allowed characters for named placeholders:
[:][a-zA-Z0-9_]+;
Alphanumeric and underscores.
Ref. https://github.com/php/php-src/blob/master/ext/pdo/pdo_sql_parser.re (this is the source)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With