| Conditions | 3 | 
| Paths | 4 | 
| Total Lines | 22 | 
| Code Lines | 17 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 1 | ||
| Bugs | 0 | Features | 0 | 
| 1 | <?php | ||
| 21 | public function backup() | ||
| 22 |   { | ||
| 23 | $DBH = $this->pdo->pdo(); | ||
| 24 |     $show = $DBH->query('SHOW TABLES'); | ||
| 25 | $tables = []; | ||
| 26 |     while ($row = $show->fetch(PDO::FETCH_NUM)) { | ||
| 27 | $tables[] = $row[0]; | ||
| 28 | } | ||
| 29 | $table_creation = ''; | ||
| 30 |     foreach ($tables as $table) { | ||
| 31 |       $result = $DBH->query("SELECT * FROM $table"); | ||
| 32 | $num_fields = $result->columnCount(); | ||
| 33 | $num_rows = $result->rowCount(); | ||
| 34 | |||
| 35 |       $pstm2 = $DBH->query("SHOW CREATE TABLE $table"); | ||
| 36 | $row2 = $pstm2->fetch(PDO::FETCH_NUM); | ||
| 37 |       $ifnotexists = str_replace('CREATE TABLE', 'CREATE TABLE IF NOT EXISTS', $row2[1]); | ||
| 38 | $table_creation .= "\n\n" . $ifnotexists . ";\n\n"; | ||
| 39 | } | ||
| 40 |     header('Content-Type: application/json'); | ||
| 41 | echo $table_creation; | ||
| 42 | exit; | ||
| 43 | } | ||
| 45 | 
Let?s assume that you have a directory layout like this:
. |-- OtherDir | |-- Bar.php | `-- Foo.php `-- SomeDir `-- Foo.phpand let?s assume the following content of
Bar.php:If both files
OtherDir/Foo.phpandSomeDir/Foo.phpare loaded in the same runtime, you will see a PHP error such as the following:PHP Fatal error: Cannot use SomeDir\Foo as Foo because the name is already in use in OtherDir/Foo.phpHowever, as
OtherDir/Foo.phpdoes not necessarily have to be loaded and the error is only triggered if it is loaded beforeOtherDir/Bar.php, this problem might go unnoticed for a while. In order to prevent this error from surfacing, you must import the namespace with a different alias: