1
0

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 5 years have passed since last update.

【Laravel】クエリ実行前にMySQLのDBコネクションのPDOにsetAttributeする。

Posted at

メモとして残します。

■やり方

下記の例では現在のDBコネクションにPDO::ATTR_EMULATE_PREPARESをtrueでセットしています。

(\DB::connection()->getPdo())->setAttribute(PDO::ATTR_EMULATE_PREPARES, true);

■余談

laravelではPDO::ATTR_EMULATE_PREPARESはデフォルトFalseですが、
LOAD DATA LOCAL INFILEステートメントを実行するときにエラーになってしまうため、PDO::ATTR_EMULATE_PREPARESをTrueにしてやる必要があります。
しかし、configのdatabase.phpで常にtrueにするのはさすがにちょっと、、、
と、なったなっため、瞬間的にTrueにすることで解決しました。

1
0
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
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?