Error in the PDO database

3

I am creating a page that saves values in the MySql database using PDO and is not writing the data. I'm using the following code:

<?php
  $conexao = new PDO('mysql:host=localhost;dbname=dbTeste', 'root', '');

  $query = "INSERT INTO names(nome, email) VALUES('Wade', '[email protected]')";

  $stmt = $conexao->prepare($query);
  $stmt->execute();
?>

But do not save the data in the database.

    
asked by anonymous 14.08.2015 / 20:57

1 answer

4

The problem is the name of your table NAMES is a mysql reserved word, in this case it is mandatory to escape the name with crase '' ''

Change:

$query = "INSERT INTO names(nome, email) VALUES('Wade', '[email protected]')";

To:

$query = "INSERT INTO 'names'(nome, email) VALUES('Wade','[email protected]')";
                      ^-----^

List of reserved words

    
14.08.2015 / 21:04