Welcome Guest, Not a member yet? Register   Sign In
return insert id from database insert function
#1

I have this function for insert data to database:
PHP Code:
    public function insertAlbumData(array $data)
    {
       $this->db->table('gallery_albums')
            ->insert($data);
    

now, how to return insertID from this function?!
Reply
#2

now, how to return insertID from this function?!


PHP Code:
public function insertAlbumData(array $data)
{
   $this->db->table('gallery_albums')
         ->insert($data);
   return 
$this->db->insertID();

You can see things I made with codeigniter here: itart.pro its not overly impressive as I have very little time to learn.
Reply
#3

Pass true as the second argument.

PHP Code:
$id $this->db->table('gallery_albums')->insert($datatrue); 

Since there is overhead associated with getting the last inserted ID from many databases, you get a small performance boost by not returning it if you don't need it. So CI4 doesn't return that by default, but makes it easy to get it if you need it.
Reply




Theme © iAndrew 2016 - Forum software by © MyBB