Airship\Engine\Continuum\Sandbox::runSQLFile PHP Method

runSQLFile() public static method

Run a SQL file
public static runSQLFile ( string $file, string $type ) : array
$file string
$type string
return array
    public static function runSQLFile(string $file, string $type) : array
    {
        $db = \Airship\get_database();
        if ($db->getDriver() !== $type) {
            // Wrong type. Abort!
            return [];
        }
        return $db->safeQuery(\file_get_contents($file));
    }

Usage Example

コード例 #1
0
ファイル: AutoUpdater.php プロジェクト: paragonie/airship
 /**
  * Automatic script execution
  *
  * @param array $autoRun
  * @return mixed
  */
 protected function autoRunScript(array $autoRun)
 {
     $ret = null;
     // Get a unique temporary file
     do {
         $script = \tempnam(ROOT . DIRECTORY_SEPARATOR . 'tmp', 'update-script-');
     } while (\file_exists($script));
     // What kind of autoRun script is it?
     switch ($autoRun['type']) {
         case 'php':
             \file_put_contents($script . '.php', Base64::decode($autoRun['data']));
             $ret = Sandbox::safeRequire($script . '.php');
             \unlink($script . '.php');
             break;
         case 'sh':
             \file_put_contents($script . '.sh', Base64::decode($autoRun['data']));
             $ret = \shell_exec($script . '.sh');
             \unlink($script . '.sh');
             break;
         case 'pgsql':
         case 'mysql':
             \file_put_contents($script . '.' . $autoRun['type'], Base64::decode($autoRun['data']));
             $ret = Sandbox::runSQLFile($script . '.' . $autoRun['type'], $autoRun['type']);
             \unlink($script . '.' . $autoRun['type']);
             break;
     }
     return $ret;
 }