简体   繁体   中英

How to connect to a database in a different server using codeigniter

I have moved my database to a different server and my applications files are still in the current server.

I have tried many ways to connect my database in the new server, But still it says

"Message: mysqli::real_connect() [mysqli.real-connect]: (HY000/2005): Unknown MySQL server host 'xxx.xxx.xxx.xxx:3306' (0)";

this is how my database.php is configured

'hostname' => 'xxx.xxx.xxx.xxx:3306',
'username' => '[my database user]',
'password' => '[my database password]',
'database' => '[my db]',
'dbdriver' => 'mysqli',
'dbprefix' => '',
'pconnect' => FALSE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,

I appriciate if anyone can provide me a solution

Commonly like this...

$db['default']['hostname'] = 'XXX.XX.XX.XXX'; //IP of server 
$db['default']['username'] = 'username';
$db['default']['password'] = 'password';
$db['default']['database'] = 'database_name';

Note:

Please allow your IP to be access for that database. Maybe that reasons why you can't connect with your remote database,

Hint:

  • In your CPanel , go to Remote Database Access Hosts and then set the host as % .. its means all IPs can be access to that database.

杜德,您正在远程访问数据库 ,因此转到新服务器的“ 远程MySQL”选项,并在“ 添加访问主机”文本框中添加写“ ”(不带引号),[以允许主机通配符输入],然后单击“ 添加主机”按钮,然后通常访问您的数据库配置( 无需更改代码

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM