如何将远程数据库与本地codeigniter一起使用?
我有运行 Codeiginiter 2.1.0 的 xampp 服务器和一个带有 MySQL 的网络服务器。 我已经可以使用 SQL-Front 进行远程访问,但是当我将相同的配置放入 CI 中时,我收到此错误:
A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: C:\xampp\htdocs\mysite\trunk\system\database\DB_driver.php
Line Number: 124
database.php:
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'myserver.com';
$db['default']['username'] = 'user_name';
$db['default']['password'] = 'pass';
$db['default']['database'] = 'database_name';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
有人知道如何连接到远程数据库吗? 感谢您的帮助!
I have xampp server running Codeiginiter 2.1.0 and a webserver with MySQL.
I already have remote access with SQL-Front but when i put the same config in CI I recive this error:
A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: C:\xampp\htdocs\mysite\trunk\system\database\DB_driver.php
Line Number: 124
database.php:
$active_group = 'default';
$active_record = TRUE;
$db['default']['hostname'] = 'myserver.com';
$db['default']['username'] = 'user_name';
$db['default']['password'] = 'pass';
$db['default']['database'] = 'database_name';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;
Someone know how to connect to remote database?
Thanks for help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我使用过这样的 mysql 连接脚本。连接脚本需要主机名、用户名和密码。我是数据库的管理员,因此可以创建或设置参数值。
I have used a mysql connect script like this. Connect script requires hostname, username and password. I am the administrator for the db, so could create or set the parameter values.
在 /application/config/database.php 文件中,您可以在
$db['default']['hostname']
设置中定义外部数据库。您最有可能需要通过网络主机查找外部数据库地址。某些主机还通过 IP 地址限制外部访问,因此您可能还需要进行设置。
In your /application/config/database.php file you can define an external database in the
$db['default']['hostname']
setting.You'll need to lookup what your external database address is through your web host most likely. Some hosts also restrict external access by IP address, so you might need to set that up also.
获得想要远程连接的 IP 地址后,请按照以下步骤操作。
Once you have the IP address that you wish to connect remotely from, follow these steps.