I\'ve tried to search for an existing answer to this problem, but the answers I find have not worked thus far.
I\'ve been attempting to use PHP to connect to a MySql
check the database name spelling at your phpMyAdmin
. Usually the name is in format user_dbname
.
For example:
cpanel username: jack,
database created: student
In your php
script, the dbname
should be jack_student
This worked for me:
If you need to change the password for MySQL 5.7.6 and later:
ALTER USER 'root'@'localhost' IDENTIFIED BY 'MyNewPass';
MySQL 5.7.5 and earlier:
SET PASSWORD FOR 'root'@'localhost' = PASSWORD('MyNewPass');
In cPanel, make sure that:
cPanelUsername_dbName
exists, with the password dbPassword
cPanelUsername_dbName
is allowed to access the database.cPanelUsername_dbName
is allowed to access the database from localhost
, 127.0.0.1
, and the IP address of your server.Your MySQL connections may use 127.0.0.1
or the IP address of your server, and MySQL will reject the connection if access isn't granted for the specific IP address used.
First check the database that you gave the proper user access to your database, which is given from Add User to databases from Mysql database section in cpanel.
after that check it again,
first try normal connection code in php,
$con = mysql_connect("localhost","cpanel_username","cpanel_password");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}