CodeIgniter Forums
database error using virtual hosts - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forumdisplay.php?fid=23)
+--- Thread: database error using virtual hosts (/showthread.php?tid=59959)



database error using virtual hosts - El Forum - 12-16-2013

[eluser]Unknown[/eluser]
Hi guys,

I'm changing my projects for to use virtual hosts on windows seven, but when I changed my first codeigniter project to use virtual hosts, acessing the project I came across the following problem:

A Database Error Occurred
Unable to connect to your database server using the provided settings.
Filename: D:\xampp\htdocs\project\system\database\DB_driver.php
Line Number: 124

But if I access like old way: http://localhost/project, no has the error, the site opened ok.

The other projects that don't using codeigniter are ok too. This is happening with only codeigniter projects.

Anybody already had the same problem or knows how to solve it?

Thanks for any helps.


database error using virtual hosts - El Forum - 12-26-2013

[eluser]InsiteFX[/eluser]
Did you edit the windows 7 host file and add a host to it?

You will need admin rights to do it

Code:
C:\Windows\System32\drivers\etc\hosts

Add: 127.0.0.1  local.dev   # or what ever your virtualhost name is.



database error using virtual hosts - El Forum - 12-26-2013

[eluser]CroNiX[/eluser]
Could it be your ENVIRONMENT setting, or some config based on ENVIRONMENT? How are you detecting/setting the ENVIRONMENT in index.php?


database error using virtual hosts - El Forum - 12-26-2013

[eluser]Unknown[/eluser]
CroNiX.

You are right! My environment configuration was not checking the new url that I set the virtual host.

Thankssss.


database error using virtual hosts - El Forum - 12-26-2013

[eluser]CroNiX[/eluser]
I check for production and testing server, and default to development. Then that won't matter, and it's also useful if you have multiple developers.

Code:
switch($env)
{
  case 'www.domain.com':
    define('ENVIRONMENT', 'production');
    break;
  case 'dev.domain.com':
    define('ENVIRONMENT', 'testing');
    break;
  default:
    define('ENVIRONMENT', 'development');
    break;
}