Home >Backend Development >PHP Tutorial >通常是用mysql还是mysqli
一般是用mysql还是mysqli啊
为什么会有mysqli啊
------解决方案--------------------
新版本的PHP都废弃mysql_系列函数了,显然建议用mysqli 啦。
------解决方案--------------------
mysqli是面向对象,当然也可以面向过程
面向对象
<br /> $mysqli=new mysqli("localhost","root","123456","test");<br /> if($mysqli->connect_error){<br /> die("连接失败".$mysqli->conect_error);<br /> }<br /><br /> $sql="select * from user1";<br /> $res=$mysqli->query($sql);<br /><br /> while($row=$res->fetch_row()){<br /> foreach($row as $k=>$v){<br /> echo "--$v";<br /> }<br /> echo "</br>";<br /> }<br /><br /> $res->free();<br /> $mysqli->close();
$mysqli=mysqli_connect("localhost","root","123456","test");<br /><br /> if(!$mysqli){<br /> die("连接失败".mysqli_connect_error($mysqli));<br /> }<br /><br /> $sql="select * from user1";<br /> $res=mysqli_query($mysqli,$sql);<br /><br /> while($row=mysqli_fetch_row($res)){<br /> foreach($row as $k=>$v){<br /> echo "--$v";<br /> }<br /> echo "</br>";<br /> }<br /><br /> mysqli_free_result($res);<br /> mysqli_close($mysqli);