使用php codeigniter连接到远程服务器数据库 [英] connecting to remote server database using php codeigniter

查看:334
本文介绍了使用php codeigniter连接到远程服务器数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在连接到远程服务器中的数据库时出现问题。
代码是/config/database.php如下:

I have a problem in connecting to the database in remote server. The code is /config/database.php is as follows:

$active_group = 'default';
$active_group = 'main';
$active_record = TRUE;

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '';
$db['default']['database'] = 'local_server';
$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;


$db['main']['hostname']='xxx.xx.xx.xx';
$db['main']['username']='user';
$db['main']['password'] ='pwd';
$db['main']['database'] = 'database1';
$db['main']['dbdriver'] = 'mysql';
$db['main']['dbprefix'] = '';
$db['main']['pconnect'] = TRUE;
$db['main']['db_debug'] = TRUE;
$db['main']['cache_on'] = FALSE;
$db['main']['cachedir'] = '';
$db['main']['char_set'] = 'utf8';
$db['main']['dbcollat'] = 'utf8_general_ci';
$db['main']['swap_pre'] = '';
$db['main']['autoinit'] = TRUE;
$db['main']['stricton'] = FALSE;

在/system/database/DB_driver.php中。我已将pconnect更改为true
var $ pconnect = TRUE;

In /system/database/DB_driver.php. I have changed the pconnect to true var $pconnect= TRUE;

从控制器说,学生我尝试连接远程服务器数据库说database1按照以下代码:

From the controller say student i try to connect the remote server database say "database1" as per the below code:

public function check_main()
    {
        $this->load->database('database1','TRUE');
    }

我收到以下错误:

Unable to connect to your database server using the provided settings.

Filename: C:\xampp\htdocs\student_attendance\system\database\DB_driver.php

Line Number: 124

In the remote server, % wildcard is given for "Remote Database Access Hosts"


推荐答案


$active_group = 'default';

$active_group = 'main';

$active_record = TRUE;


try to change above code to

$active_group = 'default';

$active_record = TRUE;


这篇关于使用php codeigniter连接到远程服务器数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆