批量插入

admin4年前php844

一条insert语句批量插入多条记录

原创|浏览:138554|更新:2017-12-19 08:21

一条insert语句批量插入多条记录


常见的insert语句,向数据库中,一条语句只能插入一条数据:


insert into persons 


(id_p, lastname , firstName, city )


values(204,'haha' , 'deng' , 'shenzhen');


(如上,仅插入了一条记录)


怎样一次insert插入多条记录呢?


使用示例:


insert into persons 


(id_p, lastname , firstName, city )


values


(200,'haha' , 'deng' , 'shenzhen'),


(201,'haha2' , 'deng' , 'GD'),


(202,'haha3' , 'deng' , 'Beijing');


这样就批量插入数据了, 遵循这样的语法,就可以批量插入数据了。


执行成功,截图:




据说,在程序开发中,一次插入多条数据,比逐次一条一条的插入数据,效率高很多


所以在程序开发的时候,使用此批量插入,也是比较不错的。


此语句在MySQL 5, postgreSQL 9.3执行通过。


相关文章

把字符按照逗号分割成数组

 <?php $cars=$_POST['shuju'];$cars=explode(',', $cars);print_r($cars)&n...

面向过程的php sqlhelp

<?php $servername = "localhost"; $username = "root"; $...

php post undefined index,PHP 中提示undefined index的解决方案

声明为空isset($_POST['user_email']),或者,empty($_POST['user_email'])在php.ini中设置error_repor...

把一个索引数组内的某个元素删除后直接转成json输出,数据格式不正确

可以看到数组格式在unset后发生变化 解决方法很简单 仅一行代码就可以解决在foreach后 增加$arr = array_values($arr);转至:https://blog.csdn.net...

php设置16位的md5加密方法

用substr函数实现substr(md5(变量),8,16);就可以实现默认的md5(变量)输出的是32位加密方法...

php再调用json_decode从字符串对象生成json对象时出现Cannot use object of type stdClass as array解决方法

php再调用json_decode从字符串对象生成json对象时,如果使用[]操作符取数据,会得到下面的错误:Cannot use object of type stdClass as array产生...

发表评论    

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。