I've seen a few errors like this, but I found no answer.
Unable to connect to database: Access denied for user ''@'localhost' to database 'socialdb'
socialdb is my database. The "Unable to connect to database:" part is located here.
$db = mysql_select_db("socialdb",$con);
if(!$db) {
die ('Unable to connect to database: ' . mysql_error());
}
I don't know what's causing this. Here are my mysql_connect details
<?php
$con = mysql_connect("localhost");
if(!$con) {
die ('Error: ' . mysql_error());
}
I need to find the root. Thanks.
I DON'T HAVE A USERNAME OR PASSWORD FOR MySQL
Should it be this?
mysql_connect("localhost","","");
You're missing username and password parameter, should be:
mysql_connect takes 3 parameters
You did not specify a user in neither
mysql_connect
or your PHP configuration.Either set
mysql.default_user
andmysql.default_password
in your PHP configuration or use the appropriate arguments formysql_connect
.Your default credentials are most likely:
even if you are not having a user. there exist 'root' user so use it
The error is pretty self-explanatory, you're not allowed to connect without specifying some credentials.
Change your call to
mysql_connect()
to something like this: