使用php codeigniter连接到远程服务器数据库

时间:2014-04-19 09:43:17

标签: php mysql database codeigniter

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

$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;

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

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"

1 个答案:

答案 0 :(得分:1)

$active_group = 'default';

$active_group = 'main';

$active_record = TRUE;


try to change above code to

$active_group = 'default';

$active_record = TRUE;