Home  >  Article  >  Backend Development  >  关于php批量插入数据,该怎么处理

关于php批量插入数据,该怎么处理

WBOY
WBOYOriginal
2016-06-13 12:15:48922browse

关于php批量插入数据

$sql = "insert into data (id,ip,data)  values('$id','$ip','$data')";<br />for($i=0;$i<100;$i++){<br />$sql.="(50),";<br />};<br />$sql = substr($sql,0,strlen($sql)-1);<br />$connect_mysql->query($sql);


提示: Call to a member function query() on a non-object in xxx on line 21(这行$connect_mysql->query($sql);)

错在什么地方,求解。新手各位大大勿嫌弃。
------解决思路----------------------
1、$connect_mysql 对象实例化错误,或不存在
2、SQL 指令拼装错误 
赞成,批量插入可以参考
$sql = "insert into data (id,ip,data)  values ";
for($i=0;$i$sqls[]="($i,'127.0.0.1',50)";
};
$sql .=join(",",$sqls);
$connect_mysql->query($sql);

Statement:
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