No Database Selected - PHP & MySQL

前端 未结 2 803
太阳男子
太阳男子 2020-12-03 22:41

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.

Erro         


        
相关标签:
2条回答
  • 2020-12-03 23:04

    I had that problem and solved it with prefixing the table name with the database name, so

     select * from database.table
    
    0 讨论(0)
  • 2020-12-03 23:22

    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';
    

    Update

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

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

    Following this, the GRANT statements above are probably unnecessary, as your host may have already worked out the correct database permissions.

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