connect external db with codeIgniter

我怕爱的太早我们不能终老 提交于 2020-01-06 02:49:08

问题


i am new in code igniter, i tried to connect with local db then successfully connected,but while connecting with external db it resulting an error

A PHP Error was encountered

Severity: Warning

Message: mysqli::real_connect(): (HY000/2003): Can't connect to MySQL server on 'xxxxx.gridserver.com' (110)

Filename: mysqli/mysqli_driver.php

Line Number: 202

Backtrace:

File: /var/www/html/restapi/application/libraries/REST_Controller.php
Line: 375
Function: __construct

File: /var/www/html/restapi/application/controllers/Project.php
Line: 26
Function: __construct

File: /var/www/html/restapi/index.php
Line: 292
Function: require_once

i am not familiar with mysql,

i searched more for it, but i have no idea what they speaking about it, is there anything to do for external db connecton

Thank you in advance!


回答1:


Check your config->database.php to ensure the $db['default']['hostname'],$db['default']['username'],$db['default']['password'],$db['default']['database'] are set correctly.

Anther possibility is you're trying to connect a MySQL server remotely but the server itself is blocking remote connection. So make sure that you are able to connect your mysql database using the same set of host, username, password through Mysql client software such as "MySQL Workbench"




回答2:


As stated by Tan See Youu, it's likely that you may have incorrect credentials in the database.php or indeed named remote connection is being blocked by the server. Though in some cases hosts offer tunnles to be used to allow remote connections through a secured connection. You might want to ask your hosting if they have a SSH tunnel that you could use if they do block direct connections.




回答3:


1.Check your application/config/database.php

$db['default'] = array(
    'dsn'   => '',
    'hostname' => 'localhost', // your database machine name, this could have localhost, ip address or domain name.
    'username' => 'yourmysluser',
    'password' => 'yourmysqlpassword',
    'database' => 'yourdb',
    'dbdriver' => 'mysqli',
  1. Check your mysql database, by default remote access to the MySQL database server is disabled for security reason. However, some time you nee to provie remote access to database server from home or a web server. You can enable remote mysql access with mysql console or phpmyadmin or another database tool dependent your host. refer to this :

Enable remote MySQL connection: ERROR 1045 (28000): Access denied for user

and

https://www.youtube.com/watch?v=xXOq9U9fzOo



来源:https://stackoverflow.com/questions/35126910/connect-external-db-with-codeigniter

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!