note 129064 added to pdostatement.bindparam
| From: | marco dot marsala at live dot it | Date: | Thu, 23 Nov 2023 08:26:19 +0000 |
| Subject: | note 129064 added to pdostatement.bindparam | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-221018@lists.php.net to get a copy of this message | ||
Examples doesn't highlight that this works as expected:
<?php
/* Execute a prepared statement by binding PHP variables */
$sth = $dbh->prepare('SELECT name, colour, calories
FROM fruit
WHERE calories < :calories AND colour = :colour');
$sth->bindParam('calories', $calories, PDO::PARAM_INT);
/* Names can be prefixed with colons ":" too (optional) */
$sth->bindParam(':colour', $colour, PDO::PARAM_STR);
$calories = 150;
$colour = 'red';
$sth->execute();
?>
calories get set to 150 in db, colour get set to red in db, because, as documentation points out:
"the variable is bound as a reference and will only be evaluated at the time that
PDOStatement::execute() is called."
----
Server IP: 45.112.84.4
Probable Submitter: 45.91.157.134 (proxied: 93.32.76.127)
----
Manual Page -- https://php.net/manual/en/pdostatement.bindparam.php
Edit -- https://main.php.net/note/edit/129064
Del: integrated -- https://main.php.net/note/delete/129064/integrated
Del: useless -- https://main.php.net/note/delete/129064/useless
Del: bad code -- https://main.php.net/note/delete/129064/bad+code
Del: spam -- https://main.php.net/note/delete/129064/spam
Del: non-english -- https://main.php.net/note/delete/129064/non-english
Del: in docs -- https://main.php.net/note/delete/129064/in+docs
Del: other reasons-- https://main.php.net/note/delete/129064
Reject -- https://main.php.net/note/reject/129064
Search -- https://main.php.net/manage/user-notes.php