1

I created an extension for joomla using:

$id=$database->insertid();

I just covered that if two users are logged on to the site will fit together perform two records in the database and then this statement will return in both cases the same value. in php you can solve this problem with the transactions.

In joomla how do I solve this problem?

Techie
  • 44,706
  • 42
  • 157
  • 243
iacoposk8
  • 11
  • 6
  • Did you mean login or register ? – Jobin Jan 23 '13 at 13:46
  • no, I want to take the last inserted id after an insert on the database, while ensuring mutual exclusion – iacoposk8 Jan 23 '13 at 14:19
  • If you are trying two insertion at the same time (Two user registered same time) The joomla works correctly you will get the last user id by using insert id function.If you do with your custom component paste your code may be something you missed. – Jobin Jan 23 '13 at 15:45

3 Answers3

1

If you have a table you are working with that extends JTable then make sure that you included the check out functionality that is optionally a part of that. THis must means adding a couple of fields like what is in the content table. This will prevent two people from editing the same row at the same time which creates a race condition in which one of the other will lose their data.

Elin
  • 6,507
  • 3
  • 25
  • 47
0

Please note that both php and joomla functions to return the last insert id rely on the mysql implementation, and mysql returns the last id inserted on the currently open connection so concurrency is not an issue

Riccardo Zorn
  • 5,590
  • 1
  • 20
  • 36
0

@iacoposk8 Your are right it might possible that in very rear case. Such time try to add current logged in user id in your sql query or any where so that it doesn't make any confict. I hope you get it what i want to say. Thanks

atpatil11
  • 438
  • 4
  • 13