PHP PDO does not insert value

0

I do not quite understand PHP, but I'm trying to create a PDO connection. The connection works fine but does not enter the values ...

follow the code:

config

define("DB_HOST", "localhost");
define("DB_USER", "root");
define("DB_PASSWORD", "root");
define("DB_NAME", "everton");

define("DB_DSN_MYSQL", 'mysql:host='.DB_HOST.';dbname='.DB_NAME);
define("DB_DSN_FIREBIRD", 'firebird:host='.DB_HOST.';dbname='.DB_NAME);

date_default_timezone_set("America/Sao_Paulo");

connection

try {
            $this->con = new PDO(DB_DSN_MYSQL, DB_USER, DB_PASSWORD);
        } catch (PDOException $exception){
            $flag['flag'] = 'CONN_FAILED';
            die(json_encode($flag));
        }

insertion

$sql = 'INSERT INTO teste (codigo, nome) VALUES (:codigo, :nome)';
    $stmt = $this->con->prepare($sql);
    $codigo = 1;
    $nome = 'teste';

    $stmt->bindValue(':codigo', $codigo);
    $stmt->bindValue(':nome', $nome);
    
asked by anonymous 14.04.2017 / 18:29

1 answer

2
  

$ stmt-> run ();

$sql = 'INSERT INTO teste (codigo, nome) VALUES (:codigo, :nome)';
$stmt = $this->con->prepare($sql);
$codigo = 1;
$nome = 'teste';

$stmt->bindValue(':codigo', $codigo);
$stmt->bindValue(':nome', $nome);
$stmt->execute();
    
14.04.2017 / 19:04