Home > Backend Development > PHP Tutorial > 在MYSQL中,怎么用PDO绑定变量的方式插入数据?

在MYSQL中,怎么用PDO绑定变量的方式插入数据?

WBOY
Release: 2016-06-06 20:40:25
Original
1231 people have browsed it

比如我的SQL语句是

<code>INSERT INTO `man_db_write`.`man_articles` (`title`,`content`,`created`) VALUES (:0_title,:0_content,:0_created),(:1_title,:1_content,:1_created)
</code>
Copy after login
Copy after login

然后我再PHP中绑定变量

<code>$stmt->bindParam(':0_title','title 1');
$stmt->bindParam(':0_content','content 1');
$stmt->bindParam(':0_created','1418103633');
$stmt->bindParam(':1_title','title 2');
$stmt->bindParam(':1_content','content 2');
$stmt->bindParam(':1_created','1418103635');
$stmt->execute();
</code>
Copy after login
Copy after login

这样批量插入数据的方法科学吗?

回复内容:

比如我的SQL语句是

<code>INSERT INTO `man_db_write`.`man_articles` (`title`,`content`,`created`) VALUES (:0_title,:0_content,:0_created),(:1_title,:1_content,:1_created)
</code>
Copy after login
Copy after login

然后我再PHP中绑定变量

<code>$stmt->bindParam(':0_title','title 1');
$stmt->bindParam(':0_content','content 1');
$stmt->bindParam(':0_created','1418103633');
$stmt->bindParam(':1_title','title 2');
$stmt->bindParam(':1_content','content 2');
$stmt->bindParam(':1_created','1418103635');
$stmt->execute();
</code>
Copy after login
Copy after login

这样批量插入数据的方法科学吗?

鸟哥~

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