header("Content-type:text/html;charset=utf-8");
define('MYSQL_HOST','127.0.0.1'); //mysql地址
define('MYSQL_PORT','3306'); // mysql 端口号
define('MYSQL_USER','root'); //用户名
define('MYSQL_PW',''); //密码
define('MYSQL_DBNAME','wuyouzhuang'); //数据库名称
//创建连接
$conn = mysqli_connect(MYSQL_HOST, MYSQL_USER, MYSQL_PW, MYSQL_DBNAME,MYSQL_PORT);
//判断连接结果
if(mysqli_connect_error($conn)){
exit("数据库连接失败,失败号".mysqli_connect_errno($conn)."失败信息:".mysqli_connect_error($conn));
}
mysqli_query($conn,"set names utf8");
//执行查询操作
//查询sql,可以换成你自己的sql
$sql = "select * from wyz_user";
$result=mysqli_query($conn,$sql);
$arr = array();
while($row =mysqli_fetch_array($result)){
array_push($arr,$row);
}
var_dump($arr);
转载于:https://blog.51cto.com/suyanzhu/2299936