How might I overcome:- SQLSTATE[28000] [1045] Access denied for user 'root'@'localhost' (using password: NO)

Links for php scripts

Moderators: egami, macek, gesf

Post Reply
IChaps
New php-forum User
New php-forum User
Posts: 115
Joined: Tue Mar 01, 2016 3:07 pm

Sun May 21, 2017 6:06 am

Hi.

Just a PDO Database query?
I'm getting the error message:-
SQLSTATE[28000] [1045] Access denied for user 'root'@'localhost' (using password: NO) when
I try and connect to the database.

Am I going wrong, or missing something?

Code: Select all

// Not my real login details
$servername =  "localhost";
$dbname =  "myownbase";
$username =  "super_ways";
$password =  "jgaab$$76";

try {
    $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password);

    // set the PDO error mode to exception
    $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

    // sql to create table
    $sql = "CREATE TABLE settings (
            setting_id INT(6) UNSIGNED AUTO_INCREMENT PRIMARY KEY,
            site_name VARCHAR(40) NOT NULL,
            welcome_text VARCHAR(50) NOT NULL,
            site_logo VARCHAR(20) NOT NULL,
            welcome_picture VARCHAR(20) NOT NULL,
            site_online VARCHAR(7) NOT NULL,
            newuser_fname INT,
            ceation_date DATE,
            default_timezone VARCHAR(70) NOT NULL,
            sys_expiry_date DATE,
            landingp VARCHAR(20) NOT NULL,
            landingp_path VARCHAR(100) NOT NULL,
            sabpass VARCHAR(50) NOT NULL,
            external_apps_install VARCHAR(8) NOT NULL,
            mail_account_name VARCHAR(50) NOT NULL,
            mail_account_from_address VARCHAR(50) NOT NULL,
            mail_popemail_address VARCHAR(100) NOT NULL,
            mail_popmail_passw VARCHAR(20) NOT NULL,
            mail_smtp_server VARCHAR(100) NOT NULL,
            mail_authent VARCHAR(1),
            reg_date TIMESTAMP  )";

    // use exec() because no results are returned
    $conn->exec($sql);
    echo "Table settings created successfully<br>";

        // Insert
    $sql = "INSERT INTO settings (
            site_name,
            welcome_text,
            site_logo,
            welcome_picture,
            site_online,
            newuser_fname,
            ceation_date,
            default_timezone,
            sys_expiry_date,
            landingp,
            landingp_path,
            sabpass,
            external_apps_install,
            mail_account_name,
            mail_account_from_address,
            mail_popemail_address,
            mail_popmail_passw,
            mail_smtp_server,
            mail_authent)

        VALUES (
            '$site_name',
            'Welcome to $site_name',
            'logo',
            'none',
            'online',
            'disabled',
            '$signupdate',
            'London',
            '$passwrenewal',
            'Default',
            'Default',
            '',
            '0',
            'Mail Account Name',
            'Account email',
            'mail add',
            'password',
            'smtp',
            'n')";


    $conn->exec($sql);
}
catch(PDOException $e) {
     echo $sql . "<br>" . $e->getMessage();
}
The above is currently under-review, and a lot of VARCHAR's will be changed or removed

Thank You.

Post Reply