CodeIgniter Forums
Unable to connect to the 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: Unable to connect to the database (/showthread.php?tid=78502)



Unable to connect to the database - kwikpedia - 01-30-2021

Just installed CodeIgniter 4.0.4 and MySQL 8.0.23, trying to do the tutorial and I'm getting this error:

Code:
ERROR - 2021-01-30 21:30:48 --> Error connecting to the database: No such file or directory
CRITICAL - 2021-01-30 21:30:48 --> Unable to connect to the database.
#0 /Users/......./ci-news/system/Database/BaseConnection.php(646): CodeIgniter\Database\BaseConnection->initialize()

I've searched and searched and I could not find a solution. In php.ini I have:

Code:
;extension=exif      ; Must be after mbstring as it depends on it
extension=mysqli
;extension=oci8_12c  ; Use with Oracle Database 12c Instant Client

and in .env

Code:
database.default.hostname = localhost
database.default.database = <database>
database.default.username = <user>
database.default.password = <pass>
database.default.DBDriver = MySQLi



RE: Unable to connect to the database - InsiteFX - 01-31-2021

Did you start MySQLi using spark?

Make sure that your username and password are correct also.


RE: Unable to connect to the database - paulbalandan - 01-31-2021

Try changing hostname from localhost to 127.0.0.1


RE: Unable to connect to the database - kwikpedia - 01-31-2021

(01-31-2021, 09:37 AM)paulbalandan Wrote: Try changing hostname from localhost to 127.0.0.1

Yes, that was it. Why's that?


The following is for whoever maintains the documentation. Perhaps they read these posts, as I could not find a way to provide feedback.
Should the documentation here be updated https://www.codeigniter.com/user_guide/tutorial/news_section.html so other people don't waste their time like I did ?