Welcome Guest, Not a member yet? Register   Sign In
Problem with transactions?
#1

[eluser]Mel [RS][/eluser]
Hi:
I'm developing a project and I've a problem with the transactionability of CI. I'll try to explaint it:

Code:
trans_start();

$id = query_1();

query_2($id);
query_3($id);
query_4($id);
query_5($id);
query_6($id);

trans_end();

My problem is, 'case I've to many users making that work and, the $id var is the same to some users while the transaction is not ended.

So, can you give me some orientation about how to make this? or implements some nested transactionability (I've searched in forums with bad luck).

Thanks in advance.
#2

[eluser]TheFuzzy0ne[/eluser]
I'm sorry, but I don't understand the question. However, the first query is clearly a select statement, which would be better appearing outside of the transaction.
#3

[eluser]Mel [RS][/eluser]
Hi thanks for your reply.

I can't leave the first query out of transaction 'cause if any of others query fails, i've to make a rollback.

In resume, my problem is when I've the $id var, 'cause while the transaction not end, other users can have the same $id and that will cause a database error.

I hope have been more clear.

Thanks in advance.
#4

[eluser]jedd[/eluser]
[quote author="Mel [RS]" date="1236803293"]
I can't leave the first query out of transaction 'cause if any of others query fails, i've to make a rollback.[/quote]

If the first query is just a select, then there's nothing to rollback from it. If you're relying on the result of that select (if that's all it is) then you might be better off trying to wrap up your updates/inserts/etc into a single query that includes the select component.

Quote:I hope have been more clear.
Don't take offence, but it's a bit hard to follow. Not sure if english is your native language - you're using abbreviations and wordage that suggests it is - but if that's the case, then you're not being especially clear. Re-reading that first message, I can't work out if you misspelt 'in case' or 'because', f.e. if english isn't your native language, then my apologies.

Quote:In resume, my problem is when I've the $id var, 'cause while the transaction not end, other users can have the same $id and that will cause a database error.

It'd be nice to know what the $id field refers to - because I can't see how other users might 'have the same one', and the idea of atomic or transactional database queries is that it doesn't matter what anyone else is doing - your transaction is guaranteed to work or not work in its entirety. The only database error you'll get is one you'll handle on the way out of the transaction - ie. by looking at trans_status(). Other users also implies they're present on other processes (separate instances of the web server, PHP, and consequently CI and the database session) which in turn implies insulation between these transactions and the variables you're using in same.
#5

[eluser]TheFuzzy0ne[/eluser]
Why would other users have the same ID? IDs should be unique, if they aren't then they are not really IDs, as they don't properly identify anything.

This is where I am confused. If you can explain why more than a single user can have the same ID, I might understand your problem a bit better.




Theme © iAndrew 2016 - Forum software by © MyBB