I just recently switched a bunch of sites over to Media Temple, and was dismayed to see that by default the sites run PHP4. Since many of my projects require PHP5 I set out to figure out how to get these sites running. A fair amount of digging through the Media Temple knowlege-base revealed the answer.
- Create a .htaccess file in the root of the site
- Add the following snippet of code and save:
Action php5-script /gs-bin/php-5.1.6-6
AddHandler php5-script .php
Update: MediaTemple GS is now running PHP 5.2.6. To enable it, use this snippet instead:
Action php5-script /gs-bin/php-5.2.6-1
AddHandler php5-script .php
CodeIgniter insert_id and db_session
September 24th, 2008
This seems rather obvious in retrospect, but this morning I encountered and issue trying to return the id value of the last record I inserted on a CMS where the record was inserted properly, but the id returned by the insert_id() helper function was always 0.
The original code was:
if($this->db->insert('posts',$data)) {
$this->db_session->set_flashdata('success','Post Added Successfully!');
redirect('/posts/edit/'.$this->db->insert_id());
}
Seemed simple enough: try to insert a record, on success set the flash message, and redirect to the record I inserted for further editing.
Well duh. The application uses the database for sessions, which meant that setting the flash message used a database insert (with no id to be returned). Once I clued into that the solution was simple, just store the id before setting the flash message:
if($this->db->insert('posts',$data)) {
$id = $this->db->insert_id();
$this->db_session->set_flashdata('success','Post Added Successfully!');
redirect('/posts/edit/'.$id);
}
Hardly mind blowing, but just an example of why you alway have to be conscience about what’s going on in the background of these helper functions when using a framework.