connecting to remote server database using php codeigniter

匿名 (未验证) 提交于 2019-12-03 01:45:01

问题:

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;

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

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');     }

I get the following error:

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:

$active_group = 'default';  $active_group = 'main';  $active_record = TRUE;   try to change above code to  $active_group = 'default';  $active_record = TRUE;  


标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!