PDO in two different INSERT?

0

Is it possible to make two prepared statements in two INSERT of different tables that I have in a record, that is, one prepared for each one?

For example, I have this:

INSERT INTO datos (nombre, email) VALUES('$nombre', '$email');
INSERT INTO usuarios (usuario, password, id_datos) VALUES('$usuario','$password_hash','$idDatos');
    
asked by Cifu 13.02.2017 в 17:43
source

1 answer

0

You can declare two prepared statements without having to execute one to declare the other:

$insert1 = "INSERT INTO datos (nombre, email) VALUES(:nombre, :email);";
$insert2 = "INSERT INTO usuarios (usuario, password, id_datos) VALUES(:usuario,:password_hash,:idDatos);";

$statement1 = $conn->prepare($insert1);
$statement2 = $conn->prepare($insert2);

$statement1->bindValue(':nombre', $nombre, \PDO::PARAM_STR);
...
$statement1->bindValue(':usuario', $usuario, \PDO::PARAM_STR);
...
    
answered by 13.02.2017 / 23:05
source