I am a beginner with PHP and with mySQL. I am trying to do something very simple. I have read through many solutions on Stack Overflow and I have tried many different things but nothing has worked. I am simply trying to connect to MySQL with PHP. I have a MySQL Active instance running. I am using a Mac. I can successfully connect to it using the following commands from the terminal:
mysql -u root -p
This then prompts me to enter my password:
Enter password:
I then type in my password. It is a throwaway password. It is "Snow1234". It then works successfully. It shows
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 8
....
mysql>
I can then enter commands in my terminal which all work correctly.
I am trying to do the same thing with php (keep in mind that I am a beginner and I have never used it before).
I have a file called form.php.
form.php:
<?php
mysql_connect('localhost','root','Snow1234');
?>
I save the file. Then, I upload the file to a URL that I own using Filezilla. Then, I visit the URL in my browser (Google Chrome):
http://www.myWebsite.com/form.php
However, it says on the website:
ERROR: Could not connect. Access denied for user 'root'@'localhost'
(using password: YES)
How do I fix this?