how to dynamically change database ip depending on the user_agent type? (e.g. connect to a replica if googlebot) |
[eluser]Unknown[/eluser]
Hello, I googled for this but couldn't find it. What I want to achieve is the following. Say I have 2 database servers. (say, A & A' - which is the replica of A) I want to direct to A' if the user_agents are bots (googlebot, bingbot etc) Can I achieve this in codeigniter by changing the config/database.php file? or do I have to change config item values in model (e.g. in __construct) using config library? I tried something like the following, but of course I can't use $this 'cos it's a config file. Code: if ($this->agent->is_robot()) I know this sounds silly, 'cos I'm trying to use a library in config file... (guess no library is loaded in this stage) Any advice is appreciated & thanks in advance!
[eluser]InsiteFX[/eluser]
It's in the CodeIgniter Users Guide. CodeIgniter USers Guide - Database Connecting
[eluser]Unknown[/eluser]
after I wrote about this. I recalled what I did earlier. basically define replica in config/database.php Code: $db['main']['hostname'] = 'XXX.XXX.XXX.XXX'; then in CI_Model.php somewhere in __construct Code: if ($this->agent->is_robot()) Then I don't need to change model code if written like '$this->r_db->query' etc. This would work nicely I think. |
Welcome Guest, Not a member yet? Register Sign In |