Reputation: 71
The below code, checks in my folder 'mysqls' for .sql files. Then I want it to execute the .sqls into the database.
<?php
$dirf = 'mysqls';
$dir = scandir($dirf);
unset($dir['0']);
unset($dir['1']);
foreach($dir as $file) {
$sql = file_get_contents($file);
$qr = $dbh->exec($sql);
}
?>
I've used die(var_dump($sql)); although it comes up with bool(false) The code finds all the files that have the .sql extension successfully, although it does not execute it.
Upvotes: 2
Views: 76
Reputation: 7433
You have to add the directory for file_get_contents():
$sql = file_get_contents($dirf . '/'. $file);
Upvotes: 1