No database selected - PHP and MySQL

I try to connect to my database, and when I run the code, I get an error. Can someone tell me what is wrong and any errors in my PHP code? Thanks.

Error: No database selected 

PHP code:

 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); ?> 
+7
source share
2 answers

If you have the wrong password and need to be corrected, run the GRANT statement to provide access to the user of your database:

 GRANT ALL PRIVILEGES ON aTable.* TO xxx@localhost IDENTIFIED BY 'password_for_xxx'; 

The foregoing provides all privileges. Often it is better to limit only what is needed. For example, if you only intend to SELECT, but do not modify the data,

 GRANT SELECT ON aTable.* TO xxx@localhost IDENTIFIED BY 'password_for_xxx'; 

Update

Since you defined the database name as dedbmysql , change your mysql_select_db() call to:

 $db = mysql_select_db("dedbmysql", $con); 

After that, the above GRANT statements are probably not needed, since your host has already developed the correct database permissions.

+14
source

I had this problem and it was solved with a table name prefix with the database name, so

  select * from database.table 
+14
source

All Articles