Codeigniter Unabletoconnecttoyourdatabaseserverusingtheprovidedsettings error solution
A few days ago, I said that Codeigniter encountered A Database Error Occurred Error. today I found the real cause of the problem: I have no permission to access the Database.
Error message:
Unable to connect to your database server using the provided settings
When searching for a database link, you can always find the answer with the premise that you already have the permission to access the database. at last, you can find the answer from the source.
Solution process:
Add the following code at the end of config/database. php for debugging.
Echo''; Print_r ($ db ['default']); echo'
'; Echo 'trying to connect to database :'. $ db ['default'] ['database']; $ dbh = mysql_connect ($ db ['default'] ['hostname'], $ db ['default'] ['username'], $ db ['default'] ['password']) or die ('cannot connect to the database because :'. mysql_error (); mysql_select_db ($ db ['default'] ['database']); echo'
Connected OK: '; die ('File:'. _ file _. '--> Line:'. _ LINE __);
When I access the website again, I am prompted that the server does not have the permission to access the database, and the server sets the access permission, everything is OK.
The lesson learned from this story is that what others have said may not be exactly correct, and it verifies the sentence "Seeing is believing ".