Viewing entries tagged with 'SQL'

Copying records from one table to another: INSERT from SELECT in SQL

24 August 2011

Tags: , ,

If you find yourself writing something like the following code, try to stop and think for a while (the example uses PHP Database Objects extension):


$insert = $dbh->prepare('INSERT INTO cheapBooks VALUES (?)');

foreach($dbh->query('SELECT ID FROM Books WHERE price < 10') as $book){
        // Insert cheap books into a temporary table
        $insert->execute(array($book['ID']));
}

0 comments | Read the full post


Интернет реклама