Help us understand the problem. What is going on with this article?

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

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

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

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

$sql = file_get_contents(database_path('dump.sql'));
DB::unprepared($sql);
kazuhei
八丁堀のスタートアップ企業で働いています。 PHPとAWSが主なお仕事。
macloud
M&Aクラウドは「テクノロジーの力で、M&Aに流通革命を」をミッションにM&Aプラットフォーム「M&Aクラウド」を開発運営するスタートアップです。
https://macloud.jp
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
Comments
No comments
Sign up for free and join this conversation.
If you already have a Qiita account
Why do not you register as a user and use Qiita more conveniently?
You need to log in to use this function. Qiita can be used more conveniently after logging in.
You seem to be reading articles frequently this month. Qiita can be used more conveniently after logging in.
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away
ユーザーは見つかりませんでした