public function executeSQL(string $filename)
    {
        $fh = @fopen($filename, "r");
        if ($fh === false)
            throw new IOException("Unable to open file '$filename'");

        $prefix = $this->driver->getTablePrefix();
        
        $statement = '';
        while (!feof($fh))
        {
            $line = fgets($fh);
            $trimmed = trim($line);

            // Skip comments
            if (substr($trimmed, 0, 2) === '--')
                continue;

            if ($line)
                $statement .= "\n" . $line;

            if (substr($trimmed, -1) === ';')
            {
                $statement = trim(str_replace('%PREFIX%', $prefix, $statement));
                $this->exec($statement);
                $statement = '';
            }
        }
        fclose($fh);
        return $this;
    }
public function executeSQL(string $filename)
    {
        $fh = @fopen($filename, "r");
        if ($fh === false)
            throw new IOException("Unable to open file '$filename'");

        $prefix = $this->driver->getTablePrefix();
        
        $statement = '';
        while (!feof($fh))
        {
            $line = fgets($fh);
            $trimmed = trim($line);

            // Skip comments
            if (substr($trimmed, 0, 2) === '--')
                continue;

            if ($line)
                $statement .= "\n" . $line;

            if (substr($trimmed, -1) === ';')
            {
                $statement = trim(str_replace('%PREFIX%', $prefix, $statement));
                $this->exec($statement);
                $statement = '';
            }
        }
        fclose($fh);
        return $this;
    }
public function executeSQL ( string $ filename ) { $ fh = @ fopen ( $ filename , "r" ) ; if ( $ fh === false ) throw new IOException ( "Unable to open file '$filename'" ) ; $ prefix = $ this -> driver -> getTablePrefix ( ) ; $ statement = '' ; while ( ! feof ( $ fh ) ) { $ line = fgets ( $ fh ) ; $ trimmed = trim ( $ line ) ; // Skip comments if ( substr ( $ trimmed , 0 , 2 ) === '--' ) continue ; if ( $ line ) $ statement .= "\n" . $ line ; if ( substr ( $ trimmed , - 1 ) === ';' ) { $ statement = trim ( str_replace ( '%PREFIX%' , $ prefix , $ statement ) ) ; $ this -> exec ( $ statement ) ; $ statement = '' ; } } fclose ( $ fh ) ; return $ this ; }
Execute a SQL file in the database.

This will scan the file for statements, skipping comment-only lines.

Occurences of %PREFIX% will be replaced with the configured table
prefix. YOU ARE STRONGLY ADVISED TO ENCLOSE ALL TABLE REFERENCES
WITH IDENTIFIER QUOTES. For MySQL use backticks, for PostgreSQL
use double quotes. Failing to do so may introduce problems when
a prefix is used that requires quoting, for example when it
includes hyphens.

There are a two basic restrictions on the format:

1) each statement should be terminated with a semi-colon
2) each semi-colon should be at the end of a line, not followed
by a comment.
3) Any line where the first two non-white space characters are --
is treated as a comment. Regardless of quotes. Therefore,
the use of -- should be avoided except for comments.

Not adhering to 1) will result in the last statement not being executed.
Not adhering to 2) will result in the semi-colon not being detected,
thus leading to the last statement not being executed.
Not adhering to 3) will result in lines being skipped.

Statements are concatenated and fed to the SQL driver, so any other
language construct understood by the database is allowed.

@param string $filename The SQL file to load and execute
@return $this Provides fluent interface
@throws PDOException When the SQL is faulty
Execute a SQL file in the database .