"No database" error even after db is selected

I selected a database, but for some strange reason, it still says that it is not selected.

Connection lines:

$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());

Inquiry:

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());

And the error is simple No database selected.

I have never seen this error before, and I tried to change a lot of things, but just didn't work.

+5
source share
6 answers

You forgot to pass the $ link variable as the link parameter.

     mysql_select_db('database', $link) or die(mysql_error());

EDIT: Try passing the database to the FROM parameter, e.g.

     SELECT * FROM `database`.`table`
+7
source

Maybe mysql user permissions for the selected database?

+2
source

, , , , , /. . , persmissions .

+2

, db .

+1

Make sure that your code is not inserted into classes and so on, if it is simply presented as is, then perhaps the "database" is invalid, double-check your values ​​and try to make it an external variable.

0
source

SOLVE Use `backticks for MYSQL reserved words ... your table name is reserved for MYSQL ... Change the name of your table.

0
source

All Articles