Cannot connect remote database |
I want get some data from aonther database, so i create a user [promission only have "SELECT"], I check connect with terminal, it's good.
but in the codeigniter-4 . the logs is : ``` ERROR - 2023-10-10 11:26:03 --> Error connecting to the database: mysqli_sql_exception: Connection refused in /www/wwwroot/example.com/vendor/codeigniter4/framework/system/Database/MySQLi/Connection.php:185 Stack trace: #0 /www/wwwroot/example.com/vendor/codeigniter4/framework/system/Database/MySQLi/Connection.php(185): mysqli->real_connect() #1 /www/wwwroot/example.com/vendor/codeigniter4/framework/system/Database/BaseConnection.php(391): CodeIgniter\Database\MySQLi\Connection->connect() #2 /www/wwwroot/example.com/vendor/codeigniter4/framework/system/Database/BaseConnection.php(574): CodeIgniter\Database\BaseConnection->initialize() #3 /www/wwwroot/example.com/app/Common.php(26): CodeIgniter\Database\BaseConnection->query() #4 /www/wwwroot/example.com/app/Controllers/Detail.php(54): get_data() #5 /www/wwwroot/example.com/vendor/codeigniter4/framework/system/CodeIgniter.php(919): App\Controllers\Detail->index() #6 /www/wwwroot/example.com/vendor/codeigniter4/framework/system/CodeIgniter.php(494): CodeIgniter\CodeIgniter->runController() #7 /www/wwwroot/example.com/vendor/codeigniter4/framework/system/CodeIgniter.php(353): CodeIgniter\CodeIgniter->handleRequest() #8 /www/wwwroot/example.com/public/index.php(79): CodeIgniter\CodeIgniter->run() #9 {main} Next CodeIgniter\Database\Exceptions\DatabaseException: Connection refused in /www/wwwroot/example.com/vendor/codeigniter4/framework/system/Database/MySQLi/Connection.php:229 Stack trace: #0 /www/wwwroot/example.com/vendor/codeigniter4/framework/system/Database/BaseConnection.php(391): CodeIgniter\Database\MySQLi\Connection->connect() #1 /www/wwwroot/example.com/vendor/codeigniter4/framework/system/Database/BaseConnection.php(574): CodeIgniter\Database\BaseConnection->initialize() #2 /www/wwwroot/example.com/app/Common.php(26): CodeIgniter\Database\BaseConnection->query() #3 /www/wwwroot/example.com/app/Controllers/Detail.php(54): get_data() #4 /www/wwwroot/example.com/vendor/codeigniter4/framework/system/CodeIgniter.php(919): App\Controllers\Detail->index() #5 /www/wwwroot/example.com/vendor/codeigniter4/framework/system/CodeIgniter.php(494): CodeIgniter\CodeIgniter->runController() #6 /www/wwwroot/example.com/vendor/codeigniter4/framework/system/CodeIgniter.php(353): CodeIgniter\CodeIgniter->handleRequest() #7 /www/wwwroot/example.com/public/index.php(79): CodeIgniter\CodeIgniter->run() #8 {main} CRITICAL - 2023-10-10 11:26:03 --> Unable to connect to the database. Main connection [MySQLi]: Connection refused in SYSTEMPATH/Database/BaseConnection.php on line 427. 1 SYSTEMPATH/Database/BaseConnection.php(574): CodeIgniter\Database\BaseConnection->initialize() 2 APPPATH/Common.php(26): CodeIgniter\Database\BaseConnection->query() 3 APPPATH/Controllers/Detail.php(54): get_data() 4 SYSTEMPATH/CodeIgniter.php(919): App\Controllers\Detail->index() 5 SYSTEMPATH/CodeIgniter.php(494): CodeIgniter\CodeIgniter->runController() 6 SYSTEMPATH/CodeIgniter.php(353): CodeIgniter\CodeIgniter->handleRequest() 7 FCPATH/index.php(79): CodeIgniter\CodeIgniter->run() ``` in my .env file, I set a database group named "remote".
The reason is "Connection refused".
I asked ChatGPT. Quote:The error you're encountering indicates that CodeIgniter is unable to connect to the database using the "remote" database group configuration specified in your .env file. The error message "Connection refused" suggests that there might be an issue with the database server, credentials, or networking.
When you say,
Quote:I check connect with terminal, it's good. is that from a terminal on the web server?
Here are some specific things to check in your .env file:
Make sure that the database.remote.hostname setting is correct. This should be the IP address or hostname of the remote database server. Make sure that the database.remote.username and database.remote.password settings are correct. These should be the credentials for the database user that you created with limited permissions. Make sure that the database.remote.database setting is correct. This should be the name of the database that you want to connect to. Once you have verified that all of the settings in your .env file are correct, you can try restarting CodeIgniter and connecting to the remote database again. |
Welcome Guest, Not a member yet? Register Sign In |