|
Posted by Lars Eighner on 06/19/07 23:48
In our last episode,
<6-6dnULCl5Sp_-XbnZ2dnUVZ_t6qnZ2d@insightbb.com>,
the lovely and talented Marcus
broadcast on comp.lang.php:
> Hello,
> Whenever the PHP documentation references the optional link_identifier
> parameter in many mysql related functions (such as mysql_query,
> mysql_insert_id, etc.), it says:
> "The MySQL connection. If the link identifier is not specified, the last
> link opened by mysql_connect() is assumed. If no such link is found, it
> will try to create one as if mysql_connect() was called with no
> arguments. If by chance no connection is found or established, an
> E_WARNING level warning is generated."
> I know that functions such as mysql_insert_id are connection specific,
> but I have not been able to find any info explicitly stating that it is
> also connection specific when link_identifier is omitted. I am about
> 99% sure that it would still be connection specific because otherwise
> these functions would be pretty useless, but could someone please
> confirm this?
I don't know what you mean by confirmation. The function as defined in the
manual clearly states what happens when the link is not specified,
namely that it defaults just as you described above.
> I just want to avoid the scenario where persons A and B are accessing
> the same script,
Really? Or different instances of the same script?
> but by the time person A runs mysql_insert_id (or some
> other mysql function), person B's connection is technically "the last
> link opened by mysql_connect()". In other words, I want to make sure
> that I can omit the link_identifier and still be confident that
> different connections will not affect each other.
First, there is no law that says you must omit default parameters if you
can. Sometimes it is a good idea to make them explicit, and it is always
never wrong to do so.
Second, I'm pretty sure you haven't figured out how two users can access the
same script, but that you mean two instances of the same script are running
at the same time. There are ways the two instances of the same script can
step on the database in such a way as to produce unexpected results --- such
as one writes to a table between queries by the other when you are counting
on the queries being sort-of simultaneous. (That is really a database
problem and it has a database solution, namely locking, but almost always
if you are cagey with your query you can avoid the necessity.) But the two
instances of the script will not mistake each other's resources.
--
Lars Eighner <http://larseighner.com/> <http://myspace.com/larseighner>
Countdown: 580 days to go.
Owing to googlegroups not screening users to eliminate spammers and other
USENET abusers, I do not see most posts from googlegroups.
[Back to original message]
|