PDO exec returning false

Asked

Viewed 55 times

2

I’m doing an online course on PHP with PDO and I’m having problems right 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 receive a bool(false)

  • I see you’re new around here, enjoy and do the tour to better understand how Sopt works

1 answer

2


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

In your code you are separating the options by comma.

Try to build the object as follows:

$pdo = new PDO('mysql:host=localhost;dbname=curso_php_oop', 'root', ''); 
  • Thanks buddy, it worked out, I’m not believing that the problem was I use spacing to make my code look cuter kkkk

Browser other questions tagged

You are not signed in. Login or sign up in order to post.