Error Connecting to Existing Database with PHP and MySQL -


I am trying to connect to a mysql database with PHP. My code in pho file is:

  try {$ pdo = new PDO ("mysql: host = localhost; dbname = BurgerBar", "root", "root"); } Hold (PDOException $ e) {$ response = "Failed to connect:"; $ Response = $ E- & gt; incoming message (); Die ($ reaction); }  

I failed to connect to

  when I run the code in my browser: SQLSTATE [42000] [1049] Unknown database 'burgerbar'  

However, when I log mysql in my terminal using the root password as root and run the

  show database; I get  
  + -------------------- + | Database | + -------------------- + + | Information_schema | | Burgerbar | | Mysql | | Performance_schema | | Test | + -------------------- +  

So it shows that it exists in mysql I am using mmp And I can not understand it.

You must replace your connection string with a local host instead of the IP that MAMP uses instead of the local host And connects to the port on which the MMP talks on mysl. Try it:

$ pdo = New PDO ("mysql: host = 127.0.0.1; ports = 5432; dbname = burgerbar"


Comments

Popular posts from this blog

c# - SignalR: "Protocol error: Unknown transport." when navigating to hub -

class - Kivy: how to instantiate a dynamic classes in python -

python - mayavi mapping a discrete colorbar on a surface -