Link to home
Create AccountLog in
Avatar of Idarac
Idarac

asked on

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

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']);
ASKER CERTIFIED SOLUTION
Avatar of gr8gonzo
gr8gonzo
Flag of United States of America image

Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
See answer
SOLUTION
Link to home
membership
Create a free account to see this answer
Signing up is free and takes 30 seconds. No credit card required.
Avatar of Idarac
Idarac

ASKER

I did some reading about the deprecation of MySQL_connection

Both of these lines will work

        $db = new PDO('mysql:host='.$config_db['host'].';dbname='.$config_db['dbname'].'', $config_db['username'], $config_db['password']);
        echo "<p>PDO works</p> ";
       
        // OPEN A CONNECTION TO THE DATA BASE SERVER AND SELECT THE DB
        $mysqli = new mysqli($config_db['host'], $config_db['username'], $config_db['password'], $config_db['dbname']);