php连接数据库

<?php

//连接数据库
$servername = "localhost";
$username = "username";
$password = "password";
$dbname = "database_name";

$conn = mysqli_connect($servername, $username, $password, $dbname);

if (!$conn) {

die("Connection failed: " . mysqli_connect_error());

}

//查询数据
$sql = "SELECT * FROM arr";
$result = mysqli_query($conn, $sql);

//输出内容
if (mysqli_num_rows($result) > 0) {

while($row = mysqli_fetch_assoc($result)) {
    echo "内容: " . $row["nr"] . "<br>";
}

} else {

echo "0 条结果";

}

mysqli_close($conn);

?>

发表评论

电子邮件地址不会被公开。 必填项已用*标注