php mysqli批量执行sql语句程序代码
本文章来给各位同学介绍PHP mysqli批量执行sql语句程序代码,有需要了解的朋友可参考参考.
mysqli 增强-批量执行sql语句,代码如下:
- <?php
-
-
-
-
- $mysqli =new MySQLi("localhost","root","root","test");
- if($mysqli->connect_error){
- die ("连接失败".$mysqli->connect_error);
- }
-
-
- $sqls="insert into user1 (name,password,email,age) values('AAA',md5('AAA'),'AAA@hu.com',25);";
- $sqls.="insert into user1 (name,password,email,age) values('BBB',md5('BBB'),'BBB@hu.com',25);";
- $sqls.="insert into user1 (name,password,email,age) values('CCC',md5('CCC'),'CCC@hu.com',25);";
-
-
-
-
- $res=$mysqli->multi_query($sqls);
-
- if(!$res){
- echo "操作失败".$mysqli->error;
- }else{
- echo "OK";
- }
- ?>
2、批量查询,代码如下:
- <?php
-
-
- $mysqli=new MySQLi("localhost","root","root","test");
- if($mysqli->connect_error){
- die("连接失败".$mysqli->connect_error);
- }
-
- $sqls="select *from user1;";
- $sqls.="desc user1";
-
-
- if($res=$mysqli->multi_query($sqls)){
-
- do{
-
- $res=$mysqli->store_result();
- while($row=$res->fetch_row()){
- foreach($row as $val){
- echo '--'.$val;
- }
- echo '<br/>';
- }
-
- $res->free();
-
- if($mysqli->more_results()){
- echo "********新的结果集***************<br/>";
- }else{
- break;
- }
- }while($mysqli->next_result());
- }
-
- $mysqli->close();
- ?>