[eluser]Unknown[/eluser]
Hello.
I'm using Codeigniter to create a small website on a subdomain. It will interogate a database on the main site, but I don't want to touch the master table, so I'd like to Create a Temporary Table.
I notice that
pconnect in
config.php defaults to TRUE, so I assume it is best to leave that as it is - with a persistent connection?
Where therefore is the best place to put the code to Create a Temporary Table, so as to avoid the 'Table already exists errors'?
Thanks for your help.
:coolsmile: UPDATE :coolsmile:
What I did originally was put a function in the model and then call it in the constructor, but this came back with a 'Table already exists error' because of Codeigniter's persistent connection.
I was wondering if there was somewhere to put this function so that it would be called once. I was thinking of a hook, but wasn't sure where to have it fire. I'd ideally have liked to have access to
$this->db but as far as I can tell anything that fired early enough would not have
$this->db.
So in the end I started my function in the model with
Code:
$sql = "DROP TABLE IF EXISTS `my_temp_table`;";
$query = $this->db->query($sql);
Now that I think about it, this is preferable, as dropping and recreating that table will ensure users will get an up to date table, rather than one which might become quite out of date, due to Codeigniter's persistent connection.
The message therefore is: if you need to Create a Temporary Table, make sure to drop it if it already exists.