protected function insertDatabaseSqlFiles($database, $statements)
    {
        $buildConnection = $this->getBuildConnection($database);
        $dsn = str_replace("@DB@", $database, $buildConnection['dsn']);
        $this->log(sprintf('  Connecting to database "%s" using DSN "%s"', $database, $dsn));

        try {

            // Set user + password to null if they are empty strings or missing
            $username = isset($buildConnection['user']) && $buildConnection['user'] ? $buildConnection['user'] : null;
            $password = isset($buildConnection['password']) && $buildConnection['password'] ? $buildConnection['password'] : null;

            $this->conn = new PDO($dsn, $username, $password);
            $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

            // Process all statements
            foreach ($statements as $statement) {
                $this->execSQL($statement);
                if (!$this->autocommit) {
                    $this->log("  Commiting transaction", Project::MSG_VERBOSE);
                    $this->conn->commit();
                }
            }
        } catch (IOException $e) {
            if (!$this->autocommit && $this->conn !== null && $this->onError == "abort") {
                try {
                    $this->conn->rollBack();
                } catch (PDOException $ex) {
                    // do nothing.
                    $this->log("  Rollback failed.");
                }
            }
            throw new BuildException($e);
        } catch (PDOException $e) {
            if (!$this->autocommit && $this->conn !== null && $this->onError == "abort") {
                try {
                    $this->conn->rollBack();
                } catch (PDOException $ex) {
                    // do nothing.
                    $this->log("  Rollback failed");
                }
            }
            throw new BuildException($e);
        }

        $this->log(sprintf('  %d of %d SQL statements executed successfully', $this->goodSql, $this->totalSql));

        return $this->goodSql;
    }
protected function insertDatabaseSqlFiles($database, $statements)
    {
        $buildConnection = $this->getBuildConnection($database);
        $dsn = str_replace("@DB@", $database, $buildConnection['dsn']);
        $this->log(sprintf('  Connecting to database "%s" using DSN "%s"', $database, $dsn));

        try {

            // Set user + password to null if they are empty strings or missing
            $username = isset($buildConnection['user']) && $buildConnection['user'] ? $buildConnection['user'] : null;
            $password = isset($buildConnection['password']) && $buildConnection['password'] ? $buildConnection['password'] : null;

            $this->conn = new PDO($dsn, $username, $password);
            $this->conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

            // Process all statements
            foreach ($statements as $statement) {
                $this->execSQL($statement);
                if (!$this->autocommit) {
                    $this->log("  Commiting transaction", Project::MSG_VERBOSE);
                    $this->conn->commit();
                }
            }
        } catch (IOException $e) {
            if (!$this->autocommit && $this->conn !== null && $this->onError == "abort") {
                try {
                    $this->conn->rollBack();
                } catch (PDOException $ex) {
                    // do nothing.
                    $this->log("  Rollback failed.");
                }
            }
            throw new BuildException($e);
        } catch (PDOException $e) {
            if (!$this->autocommit && $this->conn !== null && $this->onError == "abort") {
                try {
                    $this->conn->rollBack();
                } catch (PDOException $ex) {
                    // do nothing.
                    $this->log("  Rollback failed");
                }
            }
            throw new BuildException($e);
        }

        $this->log(sprintf('  %d of %d SQL statements executed successfully', $this->goodSql, $this->totalSql));

        return $this->goodSql;
    }
protected function insertDatabaseSqlFiles ( $ database , $ statements ) { $ buildConnection = $ this -> getBuildConnection ( $ database ) ; $ dsn = str_replace ( "@DB@" , $ database , $ buildConnection [ 'dsn' ] ) ; $ this -> log ( sprintf ( '  Connecting to database "%s" using DSN "%s"' , $ database , $ dsn ) ) ; try { // Set user + password to null if they are empty strings or missing $ username = isset ( $ buildConnection [ 'user' ] ) && $ buildConnection [ 'user' ] ? $ buildConnection [ 'user' ] : null ; $ password = isset ( $ buildConnection [ 'password' ] ) && $ buildConnection [ 'password' ] ? $ buildConnection [ 'password' ] : null ; $ this -> conn = new PDO ( $ dsn , $ username , $ password ) ; $ this -> conn -> setAttribute ( PDO :: ATTR_ERRMODE , PDO :: ERRMODE_EXCEPTION ) ; // Process all statements foreach ( $ statements as $ statement ) { $ this -> execSQL ( $ statement ) ; if ( ! $ this -> autocommit ) { $ this -> log ( "  Commiting transaction" , Project :: MSG_VERBOSE ) ; $ this -> conn -> commit ( ) ; } } } catch ( IOException $ e ) { if ( ! $ this -> autocommit && $ this -> conn !== null && $ this -> onError == "abort" ) { try { $ this -> conn -> rollBack ( ) ; } catch ( PDOException $ ex ) { // do nothing. $ this -> log ( "  Rollback failed." ) ; } } throw new BuildException ( $ e ) ; } catch ( PDOException $ e ) { if ( ! $ this -> autocommit && $ this -> conn !== null && $ this -> onError == "abort" ) { try { $ this -> conn -> rollBack ( ) ; } catch ( PDOException $ ex ) { // do nothing. $ this -> log ( "  Rollback failed" ) ; } } throw new BuildException ( $ e ) ; } $ this -> log ( sprintf ( '  %d of %d SQL statements executed successfully' , $ this -> goodSql , $ this -> totalSql ) ) ; return $ this -> goodSql ; }
Executes a set of SQL statements into the target database.

@param string $database   The name of the database, as defined in the build connections
@param array  $statements list of SQL statements (strings) to be executed

@return integer the number of successful statements

@throws BuildException
Executes a set of SQL statements into the target database .