如何将远程数据库与本地codeigniter一起使用?

发布于 2024-12-26 05:59:55 字数 1025 浏览 5 评论 0原文

我有运行 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

把时间冻结 2025-01-02 05:59:55

我使用过这样的 mysql 连接脚本。连接脚本需要主机名、用户名和密码。我是数据库的管理员,因此可以创建或设置参数值。

<?php

 // echo output below when called
 $con = mysql_connect($CFG->dbhost ,$CFG->dbuser, $CFG->dbpass);

 if (!$con){
    die('Could not connect: ' . mysql_error());
 }else{
    mysql_select_db($CFG->dbname, $con);
 }

?>

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.

<?php

 // echo output below when called
 $con = mysql_connect($CFG->dbhost ,$CFG->dbuser, $CFG->dbpass);

 if (!$con){
    die('Could not connect: ' . mysql_error());
 }else{
    mysql_select_db($CFG->dbname, $con);
 }

?>
长不大的小祸害 2025-01-02 05:59:55

在 /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.

我要还你自由 2025-01-02 05:59:55

获得想要远程连接的 IP 地址后,请按照以下步骤操作。

Log into cPanel.
Click the Remote MySQL button in the Databases section.
Enter the remote IP address in the Add Access Host section.
Click the Add Host button.

Once you have the IP address that you wish to connect remotely from, follow these steps.

Log into cPanel.
Click the Remote MySQL button in the Databases section.
Enter the remote IP address in the Add Access Host section.
Click the Add Host button.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文