【发布时间】:2015-11-02 16:58:11
【问题描述】:
<?php
$dbcon=mysqli_connect("localhost","root","","simple_login");
mysqli_select_db($dbcon,"");
?>
以上代码在db_conection.php中
在另一个文件中,我尝试访问一个名为 school 的表
if(!$_SESSION['username'])
{
header("Location: index.php");//redirect to login page to secure the welcome page without login access.
}
else
{
$user=$_SESSION['username'];
require('db_conection.php');
$ex0=mysql_query("SELECT * FROM school WHERE uid='$user'") or die(mysql_error());
$count=mysql_num_rows($ex0);
if($count)
{
echo '<script>';
echo 'alert("Profile there");';
echo '</script>';
}
}
?>
即使在 require () 之后,它也会抛出错误 No database selected。请帮忙。
【问题讨论】:
-
那么,选择一个数据库也许? php.net/manual/en/mysqli.select-db.php