I want to insert two fields from another table2 and third field from vairable
SET @id = 10;
INSERT INTO table1 (id,name,email) SELECT name, email FROM table2 ;
How do that
CodePudding user response:
Using PHP PDO you can also use bindParam
with a prepared statement:
<?php
$id = 10;
$sth = $dbh->prepare('INSERT INTO table1 (id,name,email) SELECT :id, name, email FROM table2');
$sth->bindParam('id', $id, PDO::PARAM_INT);
$sth->execute();
?>