$sql=new mysqli('localhost','root','','test'); print_r($sql); if($sql->connect_errno){ die('CONNECT ERROR:'.$sql->connect_errno); };
<?php header('content-type:text/html;charset=utf-8'); //1.连接MySQL $link=mysqli_connect('localhost','root','root') or die('数据库连接失败<br/>ERROR '.mysqli_connect_errno().':'.mysqli_connect_error()); //2.设置字符集 mysqli_set_charset($link, 'UTF8'); //3.打开指定数据库 mysqli_select_db($link, 'test1') or die('指定数据库打开失败<br/>ERROR '.mysqli_errno($link).':'.mysqli_error($link));