我创建了一个'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 />';
}
但是在浏览器中我遇到了这个错误:
未选择数据库
我真的无法确定问题出在哪里。
对不起,我知道这是一个新手问题,而且似乎已经在这里发布了几次。但我无法解决它。
谢谢你花时间和耐心。