Hi guys,
I'm trying to connect my new project with PDO, and for simple reason witch i don't know and i've no idea i'm getting
connection failedSQLSTATE[28000] [1045] Access denied for user 'www-data'@'localhost' (using password: NO)
I tried everything was in my mind, i tried log to mySql by terminal, i can log properly,and with some credencial work for another connection, native mysql, and i checked if PDO driver is enabled, and is connected, so bellow my pdo settins are:
config.php
<?php
define('DB_NAME', 'dbname');
define('DB_HOST', 'localhost');
define('DB_USER', 'root');
define('DB_PASS', 'pass');
?>
class.database.php
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
include_once 'connection.php';
class dbConnection{
protected $db_conn ;
public $db_name = DB_NAME;
public $db_host = DB_HOST;
public $db_user = DB_USER;
public $db_pass = DB_PASS ;
public function connect(){
try {
$this ->db_conn = new PDO("mysql:host = $this->db_host; dbname= $this->db_name", $this->user, $this->pass);
return $this->db_conn;
} catch (PDOException $e) {
echo 'connection failed'. $e->getMessage();
}
}
}
?>
class.address.php
<?php
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
class manageAddress{
public $link;
function __construct() {
include_once ('class.database.php');
$conn = new dbConnection();
$this->link =$conn->connect();
return $this->link;
}
function getData( $table_name, $id = null){
if(isset($id)){
$query = $this->link->query("SELECT * FROM $table_name WHERE id = '$id' ORDER BY id ASC");
}
else
{
$query = $this->link->query("SELECT * FROM $table_name ORDER BY id ASC");
}
$rowCount = $query ->rowCount();
if($rowCount >= 1)
{
$result = $query->fetchAll();
}
else
{
$result = 0;
}
return $result;
}
}
?>
getData.php
<?php
session_start();
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
include_once ('class.address.php');
$init = new manageAddress();
$table_name = 'tbl_users';
$data = $init->getData($table_name);
print_r($data);
?>
So i post all code i'm using for now, please can someone point to right side!