I'm doing a test and I want to connect to the database Tarea2
and show the table EMPLEADO
but I can not connect.
My user is root
, for simplicity of the task I do not have passwords
This is my code.
$app->get('/EMPLEADO', function(){
$pdo = new PDO('mysql:host=localhost;dbname=Tarea2','root','');
$query = "SELECT * FROM EMPLEADO";
$statement = $pdo->prepare($query);
$statement->execute();
$EMPLEADO = $statement->fetchAll(PDO::FETCH_OBJ);
echo json_encode($EMPLEADO);
});
but it shows me an error:
Slim Application Error The application could not run because of the following error:
Details
Type: PDOException Code: 1045 Message: SQLSTATE [HY000] [1045] Access denied for user 'root' @ 'localhost' (using password: NO) File: /Applications/MAMP/htdocs/tarea3/index.php Line: 52
This is my line 52
$pdo = new PDO('mysql:host=localhost;dbname=Tarea2','root','');
What am I failing? Thank you very much.