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

通常是用mysql还是mysqli

WBOY
Release: 2016-06-13 12:03:43
Original
1081 people have browsed it

一般是用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();
Copy after login

面向过程
$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);
Copy after login

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

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template