未选择数据库-PHP&的MySQL [英] No Database Selected - PHP & MySQL
问题描述
我试图连接到我的数据库,当我运行代码时,出现错误.谁能告诉我我的PHP代码中有什么错误和错误吗?谢谢.
I am trying to connect to my database and when I run the code, I get an error. Can anybody tell me what is wrong also any errors in my PHP code? Thanks.
Error: No database selected
PHP代码:
include('.conf.php');
$prof = $_GET['profile'];
$prof = addslashes(htmlentities($prof));
$query = "SELECT * FROM aTable where id = '".mysql_real_escape_string($prof)."'";
$info_array = mysql_query($query, $con) or die (mysql_error()).;
while($row = mysql_fetch_array( $info_array ))
{
echo $row['num1'];
echo "</br>";
echo $row['num2'];
echo "</br>";
echo $row['num3'];
echo "</br>";
echo $row['num4'];
};
mysql_close($con);
.conf.php 文件:
<?php
$conf['db_hostname'] = "xxx";
$conf['db_username'] = "xxx";
$conf['db_password'] = "xxx";
$conf['db_name'] = "xxx";
$conf['db_type'] = "mysql";
$con = mysql_connect('xxx', 'xxx', 'xxx') or die (mysql_error());
$db = mysql_select_db("aTable", $con);
?>
推荐答案
除非密码输入错误并需要解决,否则请运行GRANT
语句将访问权限授予数据库用户:
Unless you have the password incorrect and need to fix it, run a GRANT
statement to grant access to your database user:
GRANT ALL PRIVILEGES ON aTable.* TO xxx@localhost IDENTIFIED BY 'password_for_xxx';
以上授予所有特权.通常最好只限制需要的内容.例如,如果您仅打算选择而不是修改数据,则
The above grants all privileges. It's often better to restrict to only what's needed. For example, if you only intend to SELECT, but not modify data,
GRANT SELECT ON aTable.* TO xxx@localhost IDENTIFIED BY 'password_for_xxx';
更新
由于您已将数据库名称标识为dedbmysql
,因此将mysql_select_db()
调用更改为:
Update
Since you have identified the database name as dedbmysql
, change your mysql_select_db()
call to:
$db = mysql_select_db("dedbmysql", $con);
在此之后,上面的GRANT
语句可能是不必要的,因为您的主机可能已经计算出了正确的数据库权限.
Following this, the GRANT
statements above are probably unnecessary, as your host may have already worked out the correct database permissions.
这篇关于未选择数据库-PHP&的MySQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!