PHP批量操作-批量查询,批量添加

PHP批量操作-批量查询,批量添加

PHP批量添加数据的例子
require_once 'sqliTool.class.php';

//通过mysqli批量添加操作,这里我们批量添加三个单词
$sqliTool=new mysqli("localhost","root","123456","worddb");
if($sqliTool->connect_error){
die("连接失败".$sqliTool->connect_error);
}
$sqls="insert into words(enword,chword) values('house','房子');";
$sqls.="insert into words(enword,chword) values('tree','树,树木');";
$sqls.="insert into words(enword,chword) values('light','灯,灯光,轻,轻的');";
//一次添加多个结果
$res=$sqliTool->multi_query($sqls);
if(!$res){
echo "更新/删除失败";
return 0;
}
else{
if($sqliTool->affected_rows>0){
echo "执行成功";
return 1;
}
else{
echo "没有受影响的行数";
return 2;//没有受影响的行
}
}
$sqliTool->close();

?>

PHP批量查询的例子
//php批量获取查询的数据
$mysqli=new mysqli("localhost","root","123456","worddb");
if ($mysqli->connect_error){
die("连接失败".$mysqli->connect_error);
}
$sqls="select * from users;";
$sqls.="select * from words;";
if($res=$mysqli->multi_query($sqls)){
do{
$result=$mysqli->store_result();
while ($row=$result->fetch_row()){
foreach ($row as $key=>$val){
echo "--$val";
}
echo "
";
}
$result->free();
    if(!$mysqli->more_results()){
break;
}
echo "新的结果集";
echo "
";
}while ($mysqli->next_result());
}
$mysqli->close();
?>

你可能感兴趣的:(php)