troubleshooting Question

Access denied for user 'randyphp_tech'@'localhost' to database '_fred'

Avatar of Idarac
Idarac asked on
3 Comments2 Solutions457 ViewsLast Modified:
When I try and run the website I have 2 ways of opening the MYSQL database connection.
I am using cPanel to load MySQL database and files.

If I use PDO it works fine.

But if I use mysql_connect I get the message Access denied for user 'randyphp_tech'@'localhost' to database '_fred'

Here is my code below

       $config_db = array (
           'host' => 'localhost', // MySQL database Hostname, usually localhost
           'username' => 'randyphp_tech', // MySQL database username
           'password' => 'mzlapq01', // MySQL database password
           'dbname' => 'randyphp_fred' // MySQL database name

        $db = new PDO('mysql:host='.$config_db['host'].';dbname='.$config_db['dbname'].'',   $config_db['username'], $config_db['password']);
        echo "<p>PDO works</p> ";
        $con = mysql_connect("localhost", $config_db['username'], $config_db['password']);

Our community of experts have been thoroughly vetted for their expertise and industry experience.

Join our community to see this answer!
Unlock 2 Answers and 3 Comments.
Start Free Trial
Learn from the best

Network and collaborate with thousands of CTOs, CISOs, and IT Pros rooting for you and your success.

Andrew Hancock - VMware vExpert
See if this solution works for you by signing up for a 7 day free trial.
Unlock 2 Answers and 3 Comments.
Try for 7 days

”The time we save is the biggest benefit of E-E to our team. What could take multiple guys 2 hours or more each to find is accessed in around 15 minutes on Experts Exchange.

-Mike Kapnisakis, Warner Bros