PDO exec returning false

2

I'm doing an online course on PHP with PDO and I'm having trouble right away in the first class, with the code:

<?php

$pdo = new PDO('mysql:host = localhost, dbname = curso_php_oop', 'root', ''); //instanciando a classe do PDO, iniciando com parâmetros: 1º banco de dados, 2º usuário, 3º senha, 4º algumas opçoes
var_dump($pdo->exec('INSERT INTO usuarios (nome, sobrenome, email, senha) VALUES ("fulano", "silva", "[email protected]", "123456");')); //exec: executa a query no banco e retorna a quantidade de linhas que foram afatadas pelo comando enviado

Whenever I run this command I get a bool (false)

    
asked by anonymous 06.03.2017 / 17:38

1 answer

2

To construct a PDO object you must pass the construction options separated by a semicolon in the first argument.

In your code you are separating options by comma.

Try to construct the object as follows:

$pdo = new PDO('mysql:host=localhost;dbname=curso_php_oop', 'root', ''); 
    
06.03.2017 / 17:47