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

WBOY
Release: 2023-03-01 21:32:02
Original
1529 people have browsed it

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>
Copy after login

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>
Copy after login

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.

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!