Sunday 15 July 2012

CodeIgniter run library before database settings -


I test my Codeigniter site on the localhost then update it on a server. Many adjustment problems in switching between them. Are there.

So I want to configure it only by a constant: MYCUSTOM_SERVER_LOCATION

Then my database connection and password will be replaced by the location of my server (localhost or myhost) Accordingly configured. The only problem is that the database.php first runs the mysettings library, even in a config file instead of a library the settings have the same results.

[Updated]


application / config / autoload.php:

  ... $ autoload ['Library'] = array ('mysettings', 'database', 'session'); ...   

Application / Library / mysettings.php:

  & lt ;? Php if (! Defined ('BASEPATH')) Exit ('no permission to access any direct script'); Define ("MYCUSTOM_SERVER_LOCATION", "localhost"); Class mysettings {/////////////////////////////////////////////// /// // Options: Localhost // option: 000webhost // $ config ["mycustom_server"] = "localhost"; }  

application / config / database.php

  if (MYCUSTOM_SERVER_LOCATION == "localhost") {$ db ['default'] ['hostname'] = 'Localhost'; $ Db ['default'] ['username'] = '...'; $ Db ['default'] ['password'] = '...'; $ Db ['default'] ['database'] = '...'; } And if (MYCUSTOM_SERVER_LOCATION == "myserver") {$ db ['default'] ['hostname'] = '...'; $ Db ['default'] ['username'] = '...'; $ Db ['default'] ['password'] = '...'; $ Db ['default'] ['database'] = '...'; } Else {echo "unknown server."; Output Result:  
  encountered a PHP error Severity: Notification Message: Undefined Continued Use of MYCUSTOM_SERVER_LOCATION - Assumed ' MYCUSTOM_SERVER_LOCATION 'file name: config / database.php Line number: 51 was encountered a PHP error Seriousness: Notification Message: Undetermined Use of MYCUSTOM_SERVER_LOCATION -' MYCUSTOM_SERVER_LOCATION 'file named: config / database.php Line number: 58 Unknown server    

You set the $ activ_group variable

  / * $ activ_group variable which can be used in the application / config / database.php   

example To make the connection active, the group is only a group by default ('Default' group). * / $ Active_group = "Development"; $ Db ['development'] ['hostname'] = "localhost"; $ Db ['Evolution'] ['Username'] = "Us"; $ Db ['development'] ['password'] = ""; $ Db ['Evolution'] ['Database'] = "DB1";

No comments:

Post a Comment