面向对象:
$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];
} //遍历数据库