Welcome Guest, Not a member yet? Register   Sign In
Last Insert ID not working, returning Call to undefined method CI_DB_mysql_driver::inserted_id()
#1

[eluser]AlexKrycek[/eluser]
Hello,

We are developing a application in CodeIgniter.
This app can create pages, when we create a page (do a database insert) we want to have the last Inserted ID of that insert query.

We have below code that works on our localhost (usbwebserver and a testserver with an hoster A).
However on the server of another hoster (Hoster B) it aint working.

Code:
$data['inMainMenu'] = $_POST['inMainMenu'];
$data['internalPage'] = $_POST['internalPage'];

$succes = $this->db->insert('page', $data);
$pageId = $this->db->inserted_id();

With Hoster B we get the following error message in Direct Admin

[Thu Mar 07 10:51:18 2013] [error] [client 87.212.150.195] PHP Fatal error: Call to undefined method CI_DB_mysql_driver::inserted_id() in /home/NAME/domains/SUB.DOMAIN.nl/public_html/application/models/page_model.php on line 161, referer: http://SUB.DOMAIN.nl/

Hoster B (problem) : PHP Version 5.2.17
Hoster B (working) : PHP Version 5.3.17

in database.php we use

Code:
$active_group = 'default';
$active_record = TRUE;

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = '*******';
$db['default']['password'] = '*******';
$db['default']['database'] = 'db_TEST';
$db['default']['dbdriver'] = 'mysql';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = TRUE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = FALSE;

Anyone an idea what could be wrong with Hoster B (if its Hoster B or we) ?
Does inserted_id() depends on some PHP configuration (Hoster B recently changed some secutiry and disabled the following in PHP : exec,passthru,shell_exec,system,proc_open,popen,curl_exec,curl_multi_exec,parse_ini_file,show_source
#2

[eluser]TheFuzzy0ne[/eluser]
The method you're after is:

Code:
$this->db->insert_id();
#3

[eluser]AlexKrycek[/eluser]
Thanks that was it.
Code was written by someone else and worked on other servers (why no clue).
But changed to insert_id and excellent it worked.




Theme © iAndrew 2016 - Forum software by © MyBB