Welcome Guest, Not a member yet? Register   Sign In
mysql_insert_id?
#1

[eluser]duffy0[/eluser]
Is there any native way in the codeigniter database abstraction to do something like mysql_insert_id?

I am inserting a post from a user into a "posts" table. I then want to insert the ID generated for this post into another table called "index_queue."

I have a perl script that will run every 10 minutes or so and will create an index of all the posts whose ID's are in "index_queue."

I just need to know how I can get ID's of the posts when I insert them to the database.


Here is my code. This is an API call so I am using XML_RPCS, but I dont thing that complicates anything.

Code:
function new_post($request) {    
        $parameters = $request->output_parameters();
        
        if($this->check_auth($parameters[0], $parameters[1])) {
            $data = array(
                            'postBy'    => $parameters[0],
                            'time'        => time(),
                            'body'        => $parameters[2],
                            'location'    => $this->location->get($parameters[3])
                         );
            $this->db->insert('posts', $data);
            
            $response = array($data, 'struct');

            /* Need to somehow get the postID from the database. */
            $postID = ?????
            
            $this->posts_model->new_index_queue($postID);
            
            return $this->xmlrpc->send_response($response);
        } else {
            return $this->xmlrpc->send_error_message('100', 'Invalid Access');
        }
    }
#2

[eluser]jedd[/eluser]
[quote author="duffy0" date="1254543570"]
I just need to know how I can get ID's of the posts when I insert them to the database.
[/quote]

Yeah, it's the kind of thing you'd expect would [url="http://codeigniter.com/wiki/FAQ/"]be in the FAQ[/url], isn't it?
#3

[eluser]duffy0[/eluser]
Wow.. -slaps forehead-

Thanks.
#4

[eluser]tokyotech[/eluser]
Can I request that this be added to the manual instead of only in the FAQ?
Thanks.
#5

[eluser]Aken[/eluser]
It is in the manual... http://ellislab.com/codeigniter/user-gui...lpers.html If even says that it is in the manual in the FAQ entry, lol.
#6

[eluser]jedd[/eluser]
These computer things are mighty confusing, eh? Wink
#7

[eluser]mjsilva[/eluser]
It was so much easier when we have file cabinets with letters separating the files Tongue




Theme © iAndrew 2016 - Forum software by © MyBB