我想學習php,我無法從我的數據庫讀取任何數據!我知道與服務器的連接正在運行,但這條線似乎給我帶來了問題。php從sql數據庫讀取數據
$result = $conn->query($sql);
哪裏$sql = "SELECT firstName, middleName, lastName FROM Base";
我不知道是什麼問題,但任何提示或答案讚賞。
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1>My first PHP page</h1>
<?php
// connect to database
$user_name = "superUser";
$password = "";
$database = "Base"$server = "127.0.0.5";
// open connection to the server
$conn = new mysqli($server, $user_name, $password);
// echo "Connection to the server is open";
// check connetion
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
else {
print "Connection to the server is open";
}
// load the data from the table
$sql = "SELECT firstName, middleName, lastName FROM Base";
// echo $conn->server_info;
$result = $conn->query($sql);
if ($result) {
echo "Table was found";
}
else echo "no";
/*while($row = $result->fetch_assoc()) {
echo "id: " . $row["id"]. " - Name: " . $row["firstname"]. " " . $row["lastname"]. "<br />";
}
print $result["firstName"];// ": Number of Rows!" ;*/
// if ($result->num_rows > 0) {
// output data of each row
// close server connection
$conn->close();
?>
</body>
</html>
'mysqli的($服務器,$ USER_NAME,$密碼,$數據庫);' –
您沒有選擇你的數據庫。 – aldrin27