欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

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

程序员文章站 2023-12-30 15:07:52
...
比如我的SQL语句是
INSERT INTO `man_db_write`.`man_articles` (`title`,`content`,`created`) VALUES (:0_title,:0_content,:0_created),(:1_title,:1_content,:1_created)

然后我再PHP中绑定变量

$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();

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

回复内容:

比如我的SQL语句是

INSERT INTO `man_db_write`.`man_articles` (`title`,`content`,`created`) VALUES (:0_title,:0_content,:0_created),(:1_title,:1_content,:1_created)

然后我再PHP中绑定变量

$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();

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

鸟哥~

相关标签: php mysql pdo

上一篇:

下一篇: