user3001214
user3001214

Reputation: 71

Why is this code resulting in bool(false)?

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

Answers (1)

Marek
Marek

Reputation: 7433

You have to add the directory for file_get_contents():

$sql = file_get_contents($dirf . '/'. $file);

Upvotes: 1

Related Questions