CodeIgniter Forums
insertID() - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: insertID() (/showthread.php?tid=66670)



insertID() - superior - 11-19-2016

Hello,

Getting the following exception back when using the insertID() function.

Quote:Call to undefined method CodeIgniter\Database\MySQLi\Builder::insertID()

Don't know if i'm using it the wrong way but the following line is used inside my Model.

PHP Code:
protected $table 'Clients';

public function 
__construct()
{
 
     $this->managers = \Config\Database::connect()->table($this->table);




RE: insertID() - ridho - 11-19-2016

I think, there is no insertId() in Builder. You should use $db->insertId();


RE: insertID() - superior - 11-19-2016

(11-19-2016, 05:19 PM)ridho Wrote: I think, there is no insertId() in Builder. You should use $db->insertId();

Getting identical exception when setting it as you purposed.

Also please take a look at the following file:   "system\Database\MySQLi\Connection.php" on line "465" you can see it's "public function insertID() { ... }"

Got this information from the following documentation page: $db->insertID();


RE: insertID() - ridho - 11-19-2016

Try this, it's working for me

PHP Code:
protected $table 'Clients';

public function 
__construct()
{
      
$this->dbConn = \Config\Database::connect();
      
$this->managers $this->dbConn->table($this->table);

public function 
insertSomething(){
    
//your insert code
    
return $this->dbConn->insertID();