mysql基础连接查询

 

<?php
$servername = "127.0.0.1";
$username = "root";
$password = "root";
$dbname = "test";
// 创建连接
$conn = mysqli_connect($servername, $username, $password,$dbname);
// 检查连接
if (!$conn) {
    die("连接失败: " . mysqli_connect_error());
}
echo "连接成功<br/>";

$sql2 = "SELECT * from users WHERE `id`='1';";

$result=mysqli_query($conn,$sql2);
// $row=mysqli_fetch_array($result,MYSQLI_ASSOC);
$arr = [];
while($row = mysqli_fetch_array($result,MYSQLI_ASSOC)){
    $arr[] = $row;
}

print_r($arr);


?>

 

posted @ 2022-08-09 10:51  流浪2024  阅读(25)  评论(0编辑  收藏  举报