Then I wrote this:
You can still execute it without writing a colon
Then I wrote this:
You can still execute it without writing a colon
There are two ways to execute queries when preprocessing binding parameters in PDO:
One is the "question mark placeholder" (from left to right, one-to-one correspondence in order):
<code>$stmt = $db->prepare('UPDATE posts SET post_title = ?, post_content = ? WHERE id = ?'); $stmt->execute(array($title, $content, $id)); //所有值视作PDO::PARAM_STR处理</code>
One is "named placeholder":
<code>$stmt = $db->prepare('UPDATE posts SET post_title = :title, post_content = :content WHERE id = :id'); $stmt->execute(array(':title' => $title,':content' => $content,':id' => $id)); //所有值视作PDO::PARAM_STR处理</code>
The method of omitting the colon you mentioned can indeed be implemented, but it is still recommended to do it as the official documentation says to be safer.