Small problem with PDO

griimnak

You're a slave to the money then you die
Jul 20, 2013
957
800
SQLSTATE[HY000] [1044] Access denied for user ''@'localhost' to database 'reachphp_db, root, finger'


datbase.php
PHP:
<?php
 
/*
* ReachPHP, A private CMS written for Griimnak's site.
* Version 0.0.2
*
* Written by Griimnak
* Framework help by RastaLulz
*/
 
require './config.php';
// Connect and check database server
try {
    $dbh = new PDO('mysql:host='.$sql["host"].';dbname='.$sql["data"].', '.$sql["user"].', '.$sql["pass"].'');
    echo 'Connection was successfull.';
}
    catch(PDOException $e) {
    echo $e->getMessage();
    }
?>

Config.php
PHP:
<?php
 
/*
* ReachPHP, A private CMS written for Griimnak's site.
* Version 0.0.2
*
* Written by Griimnak
* Framework help by RastaLulz
*/
 
// Configuration variables
 
/* MySQL Hostname */ $sql['host'] = 'localhost';
/* MySQL Username */ $sql['user'] = 'root';
/* MySQL Password */ $sql['pass'] = 'finger';
/* MySQL Database */ $sql['data'] = 'reachphp_db';
 
/* Website's path */ $web['path'] = 'http://localhost';
/* Website's name */ $web['path'] = 'Griimnak\'s site';
 
?>

I don't know why access is denied. the password is correct, I've tried it in phpmyadmin. :s
 

Kryptos

prjRev.com
Jul 21, 2010
2,205
1,252
PHP:
    $dbh = new PDO("mysql:host={$sql['host']};dbname={$sql['data']}", $sql['user'], $sql['pass']);

You put everything inside a string... So it took it as a single parameter. That should work.
 

griimnak

You're a slave to the money then you die
Jul 20, 2013
957
800
PHP:
    $dbh = new PDO("mysql:host={$sql['host']};dbname={$sql['data']}", $sql['user'], $sql['pass']);

You put everything inside a string... So it took it as a single parameter. That should work.

Are you... Are you kidding me!? LMAOO That's the most embarising thing I've ever done.

Thanks Kyptoz.
 

Users who are viewing this thread

Top