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