Home  >  Article  >  Backend Development  >  The official website introduces how pdo's execute binds named parameters, but it doesn't matter if you don't write a colon.

The official website introduces how pdo's execute binds named parameters, but it doesn't matter if you don't write a colon.

WBOY
WBOYOriginal
2016-12-01 00:56:281559browse

The official website introduces how pdo's execute binds named parameters, but it doesn't matter if you don't write a colon.

Then I wrote this:

The official website introduces how pdo's execute binds named parameters, but it doesn't matter if you don't write a colon.
You can still execute it without writing a colon

Reply content:

The official website introduces how pdo's execute binds named parameters, but it doesn't matter if you don't write a colon.

Then I wrote this:

The official website introduces how pdo's execute binds named parameters, but it doesn't matter if you don't write a colon.
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.

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn