Welcome Guest, Not a member yet? Register   Sign In
insert_id function bug - Interesting
#1

[eluser]pakistanvoices[/eluser]
hi buddies
I have separate database connection for "read" and "write", I have used insert_id() to get the last inserted id, it was working fine but in last few days, I was getting problem with my functionality, after tracking the code, I have found the insert_id function is giving the wrong value. It was really astonishing for me, any one have an idea about this problem or any one face this problem, then let me know.

My code:

Database Connection :
$this->DBr = $this->load->database('db_read', TRUE);
$this->DBw = $this->load->database('db_write', TRUE);

These are define in constructor of that particular model.

Function :
$this->DBw->insert_id(); // Giving the wrong value.


Best of Luck

Javaid
#2

[eluser]WanWizard[/eluser]
Which database engine? Both databases running on the same engine (same IP and port number)?
#3

[eluser]pakistanvoices[/eluser]
hi Lab Technician,
Thanks for taking interest in my problem, I am using the INODB + MYISAM and both connection method are running on the same database, there are no different databases right now.

Regards

Javaid
#4

[eluser]WanWizard[/eluser]
The php mysql driver (i.e. not the CI code!) maintains an insert_id value per connection.

If both database instances use the same connection (which might be the case), insert_id is overwritten when you execute a second INSERT query via that same connection.
#5

[eluser]pakistanvoices[/eluser]
hi
You are right, but it was working best from last one year, it creating a problem since 2 days, and there is nothing change in code.

Regards
#6

[eluser]WanWizard[/eluser]
Behaviour usually doesn't change without reason. So there must be a change somewhere. If it's not in code, maybe in config (your app, php, mysql, the server, ...).
#7

[eluser]pakistanvoices[/eluser]
Thanks buddy, I am tracking it and I ll sure tell you about my finding. Thanks again
Good Luck.




Theme © iAndrew 2016 - Forum software by © MyBB