批量插入

admin4年前php1052

一条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...

在apache怎么常量 变量

在httpd.conf添加<IfModule mod_env.c>SetEnv 常量名 常量值</IfModule>...

php过滤emod与特殊字符

<?php  function xml_entities($string) { //过滤emod $ts_zifu= json_encode($st...

php提示Notice: Undefined index解决方法与php未定义的变量提示错误的解决方法

在php.ini配置文件里设置把error_reporting = E_ALL & ~E_DEPRECATED & ~E_STRICT修改成error_reporting = E_AL...

PHP生成json,javascript解析json

生成json<?php $arr=array();  //定义空数组 $one="111"; $two="222"; arra...

php设置cookie方法,php销毁cookie方法,php输出cookie方法,php输出cookie数量的方法

<?php //设置cookie setcookie("user_name", "frank", time()+3600); /...

发表评论    

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