thinkphp中代码块执行代码

      发布在:后端技术      评论:0 条评论
     try {
$sql=file_get_contents(dirname(__DIR__) . '/data/web.sql');
$instance = Db::connect($dbConfig,false);
// 查询一次SQL,判断连接是否正常
        $instance->execute("SELECT 1");
$instance->getConnection()->getPdo()->exec($sql);
//        thinkphp5.0可直接getPdo
//        $instance->getPdo()->exec($sql);
           // 调用原生PDO对象进行批量查询 getPdo()

//            $installError = session('install.error');
           $this->success("安装完成!", '', ['done' => 1, 'error' => 0]);
} catch (\Throwable $t) {
// Executed only in PHP 7, will not match in PHP 5
           $this->error($t->getMessage(), '', ['sql' => '', 'exception' => '']);
} catch (\Exception $e) {
// Executed only in PHP 5, will not be reached in PHP 7
           $this->error($e->getMessage(), '', ['sql' => '', 'exception' => '']);
}


相关文章
热门推荐