mysqli 的多sql语句执行问题
<?php
//对象创建
$mysqli = new mysqli('localhost', 'root', 'nagiosxi','hrsystem');
//连接是否出错
if($mysqli->connect_error)
{
die('connect database error'.mysqli_connect_error());
}
$sql = "insert into login (user, pass, email, type) values ('dengchao1', md5('dengchao123'), 'dengchao1@gmail.com', 0);";
$sql .= "insert into login (user1, pass, email, type) values ('dengchao1', md5('dengchao123'), 'dengchao1@gmail.com', 0)";
$res = $mysqli->multi_query($sql);
if($res && $mysqli->affected_rows > 0)
{
echo "insert ok <br />rows: ".$mysqli->affected_rows;
}
else
{
//$mysqli->close();
die('insert error <br />'.$mysqli->error.$mysqli->close());
}
if(!is_bool($res))
{
$res->free();
}
$sql = "select * from login";
$res = $mysqli->query($sql);
echo $mysqli->error."<br />";
if($res)
{
while($row = $res->fetch_row())
{
foreach($row as $key => $val)
{
echo "--$val";
}
echo "<br />";
}
}
if(!is_bool($res))
{
$res->free();
}
$mysqli->close();
?>