0
$servidor = "localhost";
$usuario ="root";
$senha="";
$db="pdo";
$conexao = new PDO('mysql:host = localhost; dbname = pdo', $usuario,$senha);
$stmt = $conexao->prepare('INSERT INTO tabela_pdo(nome) VALUES(:nome)');
$stmt->execute( array(':nome' => 'Lucas') );
I can’t find the error in this code, it’s not adding the data. Would someone please give me a hint? Thanks in advance for your attention.
Which error is returned?
– Fabiano Monteiro
Birth, remove these spaces, leave so
$conexao = new PDO('mysql:host=localhost;dbname=pdo', $usuario,$senha);
, Otherwise I see no error, here it works, just remove the spaces in your DSN. If it’s not that, it’s probably the port, you need to change the port. To change the door would be:$conexao = new PDO("mysql:host=$servidor;port=$port;dbname=$db", $usuario,$senha);
– Fabiano Monteiro
Thanks for the tips
– Nascimento