“No database selected” error even after a db is selected

前端 未结 6 720
再見小時候
再見小時候 2021-01-19 02:02

I have selected the database but for some weird reason it still says that it is not selected.

Connection lines:

$location = \"localhost\";
$user = \"         


        
相关标签:
6条回答
  • 2021-01-19 02:44

    Another reason why this error pops up is because the username and password which you are using to access the database may not have appropriate read/write persmissions. Especially on a shared hosting server, you will need to assign the appropriate username to the corresponding database. I recently had this problem, I had created a new database and forgot to assign persmissions for my existing username.

    0 讨论(0)
  • 2021-01-19 02:49

    SOLVED Use ` backticks for MYSQL reserved words... your table name is reserved word for MYSQL... Change your table name.

    0 讨论(0)
  • 2021-01-19 02:53

    Check if you have added the user to the db and gave him appropriate permissions.

    0 讨论(0)
  • 2021-01-19 02:56

    May be mysql's user permissions on the database you are selecting?

    0 讨论(0)
  • 2021-01-19 02:58

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

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

    EDIT: Try passing the database in the FROM parameter like

         SELECT * FROM `database`.`table`
    
    0 讨论(0)
  • 2021-01-19 03:02

    Make sure your code isn't inserted into classes and stuff, if it's just presented as is, then perhaps 'database' isn't valid, double check your values and try making it an external variable.

    0 讨论(0)
提交回复
热议问题