Blogger Information
Blog 21
fans 0
comment 0
visits 28372
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
mysqli面向对象和面向过程连接接数据库的方法
a张张张浩的博客
Original
1319 people have browsed it


面向对象:

$db=new mysqli('localhost','root','','test');


$db->set_charset("UTF8");


if (mysqli_connect_errno()){


die('Unable to connect!'). mysqli_connect_error();//注意mysqli_connect_error()新特性


}        //检查连接是否成功


$sql=""select * from gh";


$select = $db->query($sql);//执行sql语句,完全面向对象的


while($se = $select->fetch_array()){


echo $se[0];


}   //遍历数据库


面向过程:

$db=mysqli_connect('localhost','root','','test');   //链接数据库

mysqli_set_charset($db, "UTF8");    //设置数据库格式


$select=mysqli_query($db,"select * from gh"); //查询数据库


while ($se=mysqli_fetch_array($select)) {


  echo $se[0];


}                                                  //遍历数据库


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post