Home >Backend Development >PHP Tutorial >通常是用mysql还是mysqli

通常是用mysql还是mysqli

WBOY
WBOYOriginal
2016-06-13 12:03:431082browse

一般是用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);

------解决方案--------------------
首选 PDO
其次 mysqli

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn