Do you have a question? Post it now! No Registration Necessary. Now with pictures!
- Posted on
- connection specific question
June 19, 2007, 11:09 pm
rate this thread
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
I just want to avoid the scenario where persons A and B are accessing
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.
Thanks very much in advance.
Re: connection specific question
If the link identifier is omitted, the statement from above applies,
i.e. the last opened link from within the same script will be used.
It is always connection-specific.
This can't happen. Two people accessing the site at the same time means
two different script calls, two different mysql_connect() calls, hence
two different connections => mysql_insert_id() will work as expected.
The "last link opened by mysql_connect()" doesn't mean all opened links
from all running scripts on the server, it just refers to the currently
running script from the current user.
Connections from different scripts won't affect each other.
Re: connection specific question
In our last episode,
the lovely and talented Marcus
broadcast on comp.lang.php:
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.
Really? Or different instances of the same script?
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.
- » Errors won't show up even with error_reporting(E_ALL) and ini_set("display_errors","1")
- — Previous thread in » PHP Scripting Forum