9
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Laravelで複数のSQL文を実行するときはDB::unpreparedを使う

Posted at

DBのdumpのような大量のSQLをLaravelから実行するときはDB::unprepared()という関数を使うと、実行することができます。

生のSQL文を実行するときはDB::statement()をよく使いますが、複数のSQL文には対応していません。

以下はファイルに入っている複数のSQL文を読み込んで一括で実行するサンプルコードです。

$sql = file_get_contents(database_path('dump.sql'));
DB::unprepared($sql);
9
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
9
3

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?