1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
| <?php //mysqli 提供两套数据库 //面向过程 //第一种写法 mysql_connect('127.0.0.1','root','root'); mysql_select_db("cms"); mysql_set_charset("utf8"); $res=mysql_query("select *from cms_user"); $rows=[]; while($row=mysql_fetch_assoc($res)) { $rows[]=$row; } //第二种写法 $con=mysqli_connect('127.0.0.1','root','root','cms'); mysqli_set_charset($con,"utf8"); $res=mysqli_query($con,"select *from cms_user"); $rows=[]; while($row=mysqli_fetch_assoc($res)) { $rows[]=$row; } //面向对象mysqli的写法 pdo $link=new mysqli('127.0.0.1','root','root','cms'); $link->set_charset("utf8"); $res=$link->query("select *from cms_user"); $rows=[]; while($row=$res->fetch_assoc()) { $rows[]=$row; }
|