Rumah > Artikel > pembangunan bahagian belakang > 一般是用mysql还是mysqli啊
为什么会有mysqli啊
新版本的PHP都废弃mysql_系列函数了,显然建议用mysqli 啦。
mysqli是面向对象,当然也可以面向过程
面向对象
$mysqli=new mysqli("localhost","root","123456","test"); if($mysqli->connect_error){ die("连接失败".$mysqli->conect_error); } $sql="select * from user1"; $res=$mysqli->query($sql); while($row=$res->fetch_row()){ foreach($row as $k=>$v){ echo "--$v"; } echo "</br>"; } $res->free(); $mysqli->close();
$mysqli=mysqli_connect("localhost","root","123456","test"); if(!$mysqli){ die("连接失败".mysqli_connect_error($mysqli)); } $sql="select * from user1"; $res=mysqli_query($mysqli,$sql); while($row=mysqli_fetch_row($res)){ foreach($row as $k=>$v){ echo "--$v"; } echo "</br>"; } mysqli_free_result($res); mysqli_close($mysqli);
首选 PDO
其次 mysqli
首选 PDO
其次 mysqli
mysqli是面向对象,当然也可以面向过程
面向对象
$mysqli=new mysqli("localhost","root","123456","test"); if($mysqli->connect_error){ die("连接失败".$mysqli->conect_error); } $sql="select * from user1"; $res=$mysqli->query($sql); while($row=$res->fetch_row()){ foreach($row as $k=>$v){ echo "--$v"; } echo "</br>"; } $res->free(); $mysqli->close();
$mysqli=mysqli_connect("localhost","root","123456","test"); if(!$mysqli){ die("连接失败".mysqli_connect_error($mysqli)); } $sql="select * from user1"; $res=mysqli_query($mysqli,$sql); while($row=mysqli_fetch_row($res)){ foreach($row as $k=>$v){ echo "--$v"; } echo "</br>"; } mysqli_free_result($res); mysqli_close($mysqli);
PHP Data Objects (PDO)
php 内置的数据库抽象层
PHP Data Objects (PDO)
php 内置的数据库抽象层
Linux 中也用 ODBC 吗?
Linux 中也用 ODBC 吗?
PDO_SQLSRV
ODBC 是通用接口,会忽视数据库的个性特征