0
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

【CI3】dbutil() で「DB driver がありません」と言われた時の対処法(PHP 8.1対応)

Last updated at Posted at 2025-06-12

CodeIgniter 3.1.13 + PHP 8.1 で dbutil() が「DB driver がない」と怒られた話

CodeIgniter 3.1.13 を PHP 8.1 の環境で使っていて、
dbutil() を呼び出すと **「DB ドライバがない」系のエラーが出ることがありました。


🐛 発生した問題

Model で $this->load->database() しているのに、以下のようなエラーが出ました
原因は dbutil() を呼び出すときに、明示的に $this->db を渡していなかったことでした。


💡 原因の考察

CodeIgniter の dbutil ライブラリは、$this->load->dbutil() で読み込めますが、
PHP 8.1 では変数の null チェックや型の厳格さが増しているため、
内部的に $this->db がうまく渡っていないと、正しく初期化できないようです。


✅ 解決方法

$this->load->dbutil($this->db);

このように 明示的に $this->db を渡すことで、DB ドライバを正しく認識させることができます!

📝 まとめ

  • CodeIgniter 3.1.13 を PHP 8.1 で使うと、dbutil() がエラーになることがある
  • 原因は $this->load->dbutil(); のように 明示的に DB 接続を渡していないこと
  • 解決方法は $this->load->dbutil($this->db);DB 接続を明示的に渡すこと
  • エラーメッセージは「DB driver がない」「Invalid argument supplied for foreach()」など

Qiita 初投稿なので、誤りや改善点があればコメントで教えてください🙏
誰かの助けになれば嬉しいです😊

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?