简体   繁体   English

如何使用Codeigniter连接到其他服务器中的数据库

[英]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)"; “消息:mysqli :: real_connect()[mysqli.real-connect] :( HY000 / 2005):未知的MySQL服务器主机'xxx.xxx.xxx.xxx:3306'(0)”;

this is how my database.php is configured 这是我的database.php配置的方式

'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. 请允许该数据库访问您的IP 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. 在您的CPanel中 ,转到“ 远程数据库访问主机” ,然后将该主机设置为 .。这意味着所有IP都可以访问该数据库。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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