Skip to main content
adicionou 89 caracteres ao conteúdo
Fonte Link
Ivan Ferrer
  • 12,3mil
  • 3
  • 35
  • 94
Se no caso você não irá passar parâmetros como GET ou POST, etc... esta é uma boa opção.
Se no caso você não irá passar parâmetros como GET ou POST, etc... esta é uma boa opção.
adicionou 445 caracteres ao conteúdo
Fonte Link
Ivan Ferrer
  • 12,3mil
  • 3
  • 35
  • 94

Segue 34 exemplos de utilização com prepare statment através do objeto PDO:

    <?php
    /* Example one: Execute a prepared statement with placeholder */
    $sql = 'INSERT INTO tabela (cod, nome, email) VALUES (:codigo, :nome, :email)';
    
    $sth = $dbh->prepare($sql);
    $sth->execute(array(':codigo' => (int) 128,
                        ':nome' => 'ndroid',
                        ':email' => '[email protected]'));

  /* Example two: Execute a prepared statement with bind param method */
    $sql = 'INSERT INTO tabela (cod, nome, email) VALUES (:codigo, :nome, :email)';
    
    $valor1 = '128';
    $valor2 = 'ndroid';
    $valor3 = '[email protected]';

    $sth = $dbh->prepare($sql);
    $sth->bindParam(":codigo", $valor1, PDO::PARAM_INT);
    $sth->bindParam(":nome", $valor2, PDO::PARAM_STR);
    $sth->bindParam(":email", $valor3, PDO::PARAM_STR);
    $sth->execute();

 /* Example three: Execute a prepared statement with bind value method */
    $sql = 'INSERT INTO tabela (cod, nome, email) VALUES (:codigo, :nome, :email)';
    
    $sth = $dbh->prepare($sql);
    $sth->bindValue(":codigo", (int) 128, PDO::PARAM_INT);
    $sth->bindValue(":nome", 'ndroid', PDO::PARAM_STR);
    $sth->bindValue(":email", '[email protected]', PDO::PARAM_STR);
    $sth->execute();

 /* Example four: Execute a prepared statement with sequence */
    $sql = 'INSERT INTO tabela (cod, nome, email) VALUES (?, ?, ?)';
    
    $sth = $dbh->prepare($sql);
    $sth->execute(array((int) 128,
                        'ndroid',
                        '[email protected]'));
    ?>

Segue 3 exemplos de utilização com prepare statment através do objeto PDO:

    <?php
    /* Example one: Execute a prepared statement with placeholder */
    $sql = 'INSERT INTO tabela (cod, nome, email) VALUES (:codigo, :nome, :email)';
    
    $sth = $dbh->prepare($sql);
    $sth->execute(array(':codigo' => (int) 128,
                        ':nome' => 'ndroid',
                        ':email' => '[email protected]'));

  /* Example two: Execute a prepared statement with bind method */
    $sql = 'INSERT INTO tabela (cod, nome, email) VALUES (:codigo, :nome, :email)';
    
    $valor1 = '128';
    $valor2 = 'ndroid';
    $valor3 = '[email protected]';

    $sth = $dbh->prepare($sql);
    $sth->bindParam(":codigo", $valor1, PDO::PARAM_INT);
    $sth->bindParam(":nome", $valor2, PDO::PARAM_STR);
    $sth->bindParam(":email", $valor3, PDO::PARAM_STR);
    $sth->execute();

 /* Example three: Execute a prepared statement with sequence */
    $sql = 'INSERT INTO tabela (cod, nome, email) VALUES (?, ?, ?)';
    
    $sth = $dbh->prepare($sql);
    $sth->execute(array((int) 128,
                        'ndroid',
                        '[email protected]'));
    ?>

Segue 4 exemplos de utilização com prepare statment através do objeto PDO:

    <?php
    /* Example one: Execute a prepared statement with placeholder */
    $sql = 'INSERT INTO tabela (cod, nome, email) VALUES (:codigo, :nome, :email)';
    
    $sth = $dbh->prepare($sql);
    $sth->execute(array(':codigo' => (int) 128,
                        ':nome' => 'ndroid',
                        ':email' => '[email protected]'));

  /* Example two: Execute a prepared statement with bind param method */
    $sql = 'INSERT INTO tabela (cod, nome, email) VALUES (:codigo, :nome, :email)';
    
    $valor1 = '128';
    $valor2 = 'ndroid';
    $valor3 = '[email protected]';

    $sth = $dbh->prepare($sql);
    $sth->bindParam(":codigo", $valor1, PDO::PARAM_INT);
    $sth->bindParam(":nome", $valor2, PDO::PARAM_STR);
    $sth->bindParam(":email", $valor3, PDO::PARAM_STR);
    $sth->execute();

 /* Example three: Execute a prepared statement with bind value method */
    $sql = 'INSERT INTO tabela (cod, nome, email) VALUES (:codigo, :nome, :email)';
    
    $sth = $dbh->prepare($sql);
    $sth->bindValue(":codigo", (int) 128, PDO::PARAM_INT);
    $sth->bindValue(":nome", 'ndroid', PDO::PARAM_STR);
    $sth->bindValue(":email", '[email protected]', PDO::PARAM_STR);
    $sth->execute();

 /* Example four: Execute a prepared statement with sequence */
    $sql = 'INSERT INTO tabela (cod, nome, email) VALUES (?, ?, ?)';
    
    $sth = $dbh->prepare($sql);
    $sth->execute(array((int) 128,
                        'ndroid',
                        '[email protected]'));
    ?>
adicionou 6 caracteres ao conteúdo
Fonte Link
Ivan Ferrer
  • 12,3mil
  • 3
  • 35
  • 94
    <?php
    /* Example one: Execute a prepared statement with placeholder */
    $sql = 'INSERT INTO tabela (cod, nome, email) VALUES (:codigo, :nome, :email)';
    
    $sth = $dbh->prepare($sql);
    $sth->execute(array(':codigo' => (int) 128,
                        ':nome' => 'ndroid',
                        ':email' => '[email protected]'));

  /* Example two: Execute a prepared statement with bind method */
    $sql = 'INSERT INTO tabela (cod, nome, email) VALUES (:codigo, :nome, :email)';
    
    $valor1 = '128';
    $valor2 = 'ndroid';
    $valor3 = '[email protected]';

    $sth = $dbh->prepare($sql);
    $sth->bindParam(":codigo", $valor1, PDO::PARAM_INT);
    $sth->bindParam(":nome", $valor2, PDO::PARAM_STR);
    $sth->bindParam(":email", $valor3, PDO::PARAM_STR);
    $sth->execute();

 /* Example three: Execute a prepared statement with sequence */
    $sql = 'INSERT INTO tabela (cod, nome, email) VALUES (?, ?, ?)';
    
    $sth = $dbh->prepare($sql);
    $sth->execute(array((int) 128,
                        'ndroid',
                        '[email protected]'));
    ?>
    <?php
    /* Example one: Execute a prepared statement with placeholder */
    $sql = 'INSERT INTO tabela (cod, nome, email) VALUES (:codigo, :nome, :email)';
    
    $sth = $dbh->prepare($sql);
    $sth->execute(array(':codigo' => (int) 128,
                        ':nome' => 'ndroid',
                        ':email' => '[email protected]'));

  /* Example two: Execute a prepared statement with bind method */
    $sql = 'INSERT INTO tabela (cod, nome, email) VALUES (:codigo, :nome, :email)';
    
  $valor1 = '128';
  $valor2 = 'ndroid';
  $valor3 = '[email protected]';

    $sth = $dbh->prepare($sql);
    $sth->bindParam(":codigo", $valor1, PDO::PARAM_INT);
    $sth->bindParam(":nome", $valor2, PDO::PARAM_STR);
    $sth->bindParam(":email", $valor3, PDO::PARAM_STR);
    $sth->execute();

 /* Example three: Execute a prepared statement with sequence */
    $sql = 'INSERT INTO tabela (cod, nome, email) VALUES (?, ?, ?)';
    
    $sth = $dbh->prepare($sql);
    $sth->execute(array((int) 128,
                        'ndroid',
                        '[email protected]'));
    ?>
    <?php
    /* Example one: Execute a prepared statement with placeholder */
    $sql = 'INSERT INTO tabela (cod, nome, email) VALUES (:codigo, :nome, :email)';
    
    $sth = $dbh->prepare($sql);
    $sth->execute(array(':codigo' => (int) 128,
                        ':nome' => 'ndroid',
                        ':email' => '[email protected]'));

  /* Example two: Execute a prepared statement with bind method */
    $sql = 'INSERT INTO tabela (cod, nome, email) VALUES (:codigo, :nome, :email)';
    
    $valor1 = '128';
    $valor2 = 'ndroid';
    $valor3 = '[email protected]';

    $sth = $dbh->prepare($sql);
    $sth->bindParam(":codigo", $valor1, PDO::PARAM_INT);
    $sth->bindParam(":nome", $valor2, PDO::PARAM_STR);
    $sth->bindParam(":email", $valor3, PDO::PARAM_STR);
    $sth->execute();

 /* Example three: Execute a prepared statement with sequence */
    $sql = 'INSERT INTO tabela (cod, nome, email) VALUES (?, ?, ?)';
    
    $sth = $dbh->prepare($sql);
    $sth->execute(array((int) 128,
                        'ndroid',
                        '[email protected]'));
    ?>
removeu 3 caracteres do conteúdo
Fonte Link
Ivan Ferrer
  • 12,3mil
  • 3
  • 35
  • 94
Carregando
adicionou 20 caracteres ao conteúdo
Fonte Link
Ivan Ferrer
  • 12,3mil
  • 3
  • 35
  • 94
Carregando
adicionou 20 caracteres ao conteúdo
Fonte Link
Ivan Ferrer
  • 12,3mil
  • 3
  • 35
  • 94
Carregando
adicionou 178 caracteres ao conteúdo
Fonte Link
Ivan Ferrer
  • 12,3mil
  • 3
  • 35
  • 94
Carregando
Fonte Link
Ivan Ferrer
  • 12,3mil
  • 3
  • 35
  • 94
Carregando