“未选择数据库";即使选择了db后也会发生错误 [英] "No database selected" error even after a db is selected
本文介绍了“未选择数据库";即使选择了db后也会发生错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我选择了数据库,但是出于某些奇怪的原因,它仍然说未选择数据库.
I have selected the database but for some weird reason it still says that it is not selected.
连接线:
$location = "localhost";
$user = "user";
$pass = "pass";
//Database Selection
$link = mysql_connect($location, $user, $pass);
if (!$link) {
die('Could not connect: ' . mysql_error());
}
//Database Selection
mysql_select_db('database') or die(mysql_error());
查询:
while ($row_fpages = mysql_fetch_array($result_fanpage))
{
if ( $row_fpages['client'] == NULL ) {
//GRAPHS
$sql = "SELECT date, likes FROM statistics_pages WHERE idnum='".$_COOKIE['id']."' AND page_name = ".$row_fpages['page_name']." LIMIT 7";
$result_apps = mysql_query($sql) or die(mysql_error());
错误是普通的No database selected
.
我以前从未见过此错误,因此我尝试更改了许多内容,但它却无法正常工作.
I have never seen this error before and i tried to change a lot of things but its just not working.
推荐答案
您忘了将变量$ link用作链接参数.
You forgot to pass the variable $link as the link parameter.
mysql_select_db('database', $link) or die(mysql_error());
编辑:尝试在FROM参数中传递数据库,例如
Try passing the database in the FROM parameter like
SELECT * FROM `database`.`table`
这篇关于“未选择数据库";即使选择了db后也会发生错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文