您的位置:首页 > 编程语言 > PHP开发

PHP学习 mysqli执行多条语句

2014-03-10 23:26 260 查看
<?php
$mysqli=new mysqli("localhost", "root", "123456", "xsphpdb");

//有结果集多个select语句
$sqls="select current_user();";
$sqls.="desc shops;";
$sqls.="select * from shops;";
$sqls.="select current_date()";

if($mysqli->multi_query($sqls)){
echo "执行成功!<br>";
do{
$result=$mysqli->store_result();

echo '<table align="center" border="1" width='.(100*$result->field_count).'>';
echo '<tr>';
while($field=$result->fetch_field()){
echo '<th>'.$field->name.'</th>';
}
echo '</tr>';

while($row=$result->fetch_assoc()){
echo '<tr>';
foreach($row as $col){
echo '<td>'.$col.'</td>';
}
echo '</tr>';
}

echo '</table>';

if($mysqli->more_results()){
echo '<p>--<p>--<p>';
}

}while($mysqli->next_result());

}else{
echo "ERROR:".$mysqli->errno."--".$mysqli->error;
}

$mysqli->close();
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: