Welcome Guest, Not a member yet? Register   Sign In
How do I get the autoincremented ID of the latest inserted row.
#1

(This post was last modified: 10-15-2022, 10:55 PM by davecoventry.)

My code:
PHP Code:
    $this->db->simpleQuery('Use D'.$id);
    $this->db->table('drawings')->insert(array("name"=>$fname));
    return $this->db->insertID(); 

This returns a model object, but I need the number of the ID.
if I use
PHP Code:
$this->db->insert_id(); 

I get an error which says that insert_id() is an undefined method.

Code:
+----------+--------------+------+-----+---------------------+----------------+
| Field    | Type        | Null | Key | Default            | Extra          |
+----------+--------------+------+-----+---------------------+----------------+
| id      | int(9)      | NO  | PRI | NULL                | auto_increment |
| name    | varchar(255) | YES  |    | NULL                |                |
| revision | char(3)      | NO  |    | NULL                |                |
| date    | timestamp    | NO  |    | current_timestamp() |                |
+----------+--------------+------+-----+---------------------+----------------+
~ Dave
Reply
#2

PHP Code:
$this->db->insertID() 
It returns an integer here...
Reply
#3

It's suddenly started working for me too.

I have no idea what I was doing wrong, but it was obviously something stupid.

Thanks for your response, and sorry to have wasted everybody's time (including my own!).
~ Dave
Reply




Theme © iAndrew 2016 - Forum software by © MyBB