CodeIgniter Forums
CI Shield setup: can't connect to database - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: Installation & Setup (https://forum.codeigniter.com/forumdisplay.php?fid=9)
+--- Thread: CI Shield setup: can't connect to database (/showthread.php?tid=92948)



CI Shield setup: can't connect to database - SpingMan - 05-23-2025

I've run into a problem that is driving me nuts. I installed CI4.6.1 and everything went as expected. I need an authentication system, so I turned to CI Shield. Followed the docs and installation seemed to run smoothly. And that's when things went south: ran the setup through spark - everything worked until the last step and this got thrown at me:
Code:
Running all new migrations...
[CodeIgniter\Database\Exceptions\DatabaseException]
Unable to connect to the database.
Main connection [MySQLi]: No such file or directory
at SYSTEMPATH/Database/BaseConnection.php:467
I double checked my database config and everything seemed to be fine:

Code:
public local -> array (20) [
        'DSN' => string (0) ""
        'hostname' => string (9) "localhost"
        'username' => string (4) "root"
        'password' => string (4) "root"
        'database' => string (10) "benzaiten2"
        'DBDriver' => string (6) "MySQLi"
        'DBPrefix' => string (0) ""
        'pConnect' => boolean false
        'DBDebug' => boolean true
        'charset' => string (7) "utf8mb4"
        'DBCollat' => string (18) "utf8mb4_general_ci"
        'swapPre' => string (0) ""
        'encrypt' => boolean false
        'compress' => boolean false
        'strictOn' => boolean false
        'failover' => array (0) []
        'port' => integer 8889
        'numberNative' => boolean false
        'foundRows' => boolean false
        'dateFormat' => array (3) [
            'date' => string (5) "Y-m-d"
            'datetime' => string (11) "Y-m-d H:i:s"
            'time' => string (5) "H:i:s"
        ]

    ]
I changed "localhost" to "127.0.0.1",  just as a test and tried running the migration again, and got the same result. I checked the connection with both the CLI and a PHP script and had no issues.
I'm using MAMP as my development enviroment, and it's running PHP8.3.9 and MySQL8.0.35.
Any suggestions or pointers in the right direction would be greatly appreciated.


RE: CI Shield setup: can't connect to database - InsiteFX - 05-24-2025

Check your MySQLi my.ini port number it is usually 3306


RE: CI Shield setup: can't connect to database - SpingMan - 05-28-2025

(05-24-2025, 09:07 PM)InsiteFX Wrote: Check your MySQLi my.ini port number it is usually 3306
Thanks for the suggestion, but it didn't help: for whatever reason, MAMP sets its default ports for Apache and MySQL at 8888 and 8889 respectively, and I have not changed those settings. I was also able to access the database through localhost:8889 through other scripts and the terminal, so that doesn't appear to be the problem.


RE: CI Shield setup: can't connect to database - InsiteFX - 05-28-2025

That is strange, the only time I get an error on a database connection is if I forget to create a
database connection in my PhpStorm editor, but then I' m running on Windows 11 Rro.


RE: CI Shield setup: can't connect to database - gosocial2 - 05-30-2025

(05-28-2025, 05:51 PM)SpingMan Wrote:
(05-24-2025, 09:07 PM)InsiteFX Wrote: Check your MySQLi my.ini port number it is usually 3306
Thanks for the suggestion, but it didn't help: for whatever reason, MAMP sets its default ports for Apache and MySQL at 8888 and 8889 respectively, and I have not changed those settings. I was also able to access the database through localhost:8889 through other scripts and the terminal, so that doesn't appear to be the problem.

Are you using MAMP for Windows? Even the free version of MAMP for Mac should allow you to use ports 80 and 3306 (web server & Db respectively).
I had published an end-to-end tutorial video on showing how to set up the free version of MAMP (on macOS) for frameworks like CodeIgniter:

How to Set Up a Virtual Host on Free MAMP for Frameworks like CodeIgniter 4 and Laravel  

Near the exact timestamp suffixed to the link above, you should see where exactly to customize default MAMP ports.