我創建了一個「db.php中」文件,我做我的數據庫連接:沒有數據庫中選擇
$db_user = 'usprojus';
$db_pass = 'xxxxxx';
$db_host = 'localhost';
// Verbinden
$dblink = mysqli_connect($db_host, $db_user, $db_pass);
// Datenbank "myproject" auswaehlen
// Entspricht "USE myproject;"
$selected = mysqli_select_db($dblink, 'myproject');
if (!$selected) {
die ('Cannot use DB : '.mysqli_error($dblink));
}
mysqli_set_charset($dblink, 'utf8');
爲了測試工作我想從我的'用戶的數據表:
require_once('db.php');
// Get all the data from the "users" table
$result = mysql_query("SELECT * FROM users")
or die(mysql_error());
// keeps getting the next row until there are no more to get
while($row = mysql_fetch_array($result)) {
// Print out the contents of each row into a table
echo 'user_id: '.$row['user_id'].'<br />';
echo 'date_registered: '.$row['date_registered'].'<br />';
echo 'last_login: '.$row['last_login'].'<br />';
echo 'username: '.$row['username'].'<br />';
echo 'email: '.$row['email'].'<br />';
echo 'password: '.$row['password'].'<br />';
echo 'photo: '.$row['photo'].'<br />';
echo 'description: '.$row['description'].'<br />';
echo 'notify: '.$row['notify'].'<br />';
}
但我得到這個錯誤在瀏覽器:
沒有數據庫中選擇
對於我的生活,我無法弄清楚問題出在哪裏。
對不起,我知道這是一個新手問題,它好像已經發布了幾次。但我無法弄清楚。
謝謝你的時間和耐心。
@弗雷德-II爲什麼你會將此標記爲重複它已經連續4年後問? – PartisanEntity 2016-12-16 09:19:31
看到這個問答https://meta.stackoverflow.com/q/345095/1415724它會回答你的上述問題。 – 2017-03-07 23:23:06