1

I am using CodeIgniter v2.1.3 to implement MVC in a work environment. Using these database configuratons:

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

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'ctejada';
$db['default']['password'] = 'XXXX';
$db['default']['database'] = 'here_goes_database_name';
$db['default']['dbdriver'] = 'mysqli';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$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;

Once I change the hostname to anything different than localhost, it says:

A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: core/Loader.php
Line Number: 346

Even if its just 127.0.0.1

I've been stuck here for almost 2 days, with no answer.

ctejada
  • 29
  • 5
  • Where do you work? On localhost or hosting? – Winston Feb 22 '13 at 19:56
  • Hosting. But just for testing purposes I use localhost. – ctejada Feb 22 '13 at 19:57
  • You should use only the settings that who gave you the hoster. If there is no connection then you have not set all required the connections settings or set incorrectly – Winston Feb 22 '13 at 20:04
  • I'm not sure what the actual question is. Does this work properly when you set to localhost but then fail when you try to point to another host? If that's the case, I'd try to connect to the other database server from the command line using the same settings. My guess is you'll discover that the problem is not in your code but in your server configuration. – Jerry Feb 22 '13 at 20:04
  • Already done that. Everything goes swell. I even created a PHP Script that just connects to the host, and it works. The problem is in CodeIgniter. – ctejada Feb 22 '13 at 20:07
  • @Winston, I am using the settings that the "hoster" gave me. – ctejada Feb 22 '13 at 20:08
  • @ctejada Try not to change "localhost", for some hosting that works. – Winston Feb 22 '13 at 20:17
  • I need to connect to a different database. That's the whole issue. It cannot remain localhost. – ctejada Feb 22 '13 at 20:23
  • Check this comment http://stackoverflow.com/questions/8107449/connecting-to-a-remote-database-through-codeigniter#comment9957745_8107485 – Vassilis Barzokas Feb 22 '13 at 21:11
  • Thanks a lot. But the thing is I am able to connect with the MySQL client via CLI, and using a PHP script that I created just for that purposes. – ctejada Feb 22 '13 at 21:21

2 Answers2

0

$db[‘default’][‘db_debug’] = false, as it has been discussed here at ellislab forums, but I'm still not sure why that kind of change could solve the issue, it seems to be related to the OS that host the server.

dennisbot
  • 950
  • 1
  • 11
  • 22
0

If someone experiments this difficulties, on a Linux Box; check SE Linux is not denying any connections to external databases httpd. If it is, the command:

setsebool -P httpd_can_network_connect_db 1

can help you fix it.

ctejada
  • 29
  • 5