Mulitple users (scripts) same login? Is this a problem

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
User avatar
Kadanis
Forum Contributor
Posts: 180
Joined: Tue Jun 20, 2006 8:55 am
Location: Dorset, UK
Contact:

Mulitple users (scripts) same login? Is this a problem

Post by Kadanis »

Hi

Hope someone can help.

I have numerous PHP scripts that all access the same database, so I used the same username and password each time a connection was needed.

Now I have started to run some processes via cron and there is a recurring situation where more that 1 script will run at the same time and try to access the database.

My question is, would this be a problem, i.e would one script kick another one out if they are both using the same log in at the same time to access the same database. Should I be providing each script with its own user name, password and access rights?

The reason I ask is that I've started noticing some funny behaviour since this situation arose and I wondered if this was the cause.

Thanks in advance for any replies ;)
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

That's not a problem.

When you connect to a database, by let's say mysql_connect(), a link to that database is created. If a new script runs (whether it's on a cron or not) it will establish a new link to the database. Two links, two scripts, same database = no problem.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
Kadanis
Forum Contributor
Posts: 180
Joined: Tue Jun 20, 2006 8:55 am
Location: Dorset, UK
Contact:

Post by Kadanis »

even if they have the same login details. like the two examples below running concurrently.

Code: Select all

/** 
 *script 1
*/

$mysql = mysql_connect('localhost','user1','pass1');
mysql_select_db('my_db');

//do somthing

mysql_close($mysql);


/**
 * script 2
*/
$mysql = mysql_connect('localhost','user1','pass1');
mysql_select_db('my_db');

//do somthing else

mysql_close($mysql);
User avatar
mikeq
Forum Regular
Posts: 512
Joined: Fri May 03, 2002 3:33 am
Location: Edinburgh, Scotland

Post by mikeq »

no problem at all.
User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

I use one connection for all of my scripts across the whole website (hundreds of pages). I'm sure a lot of these connections are made simultaenously, and I have no problems at all.
Set Search Time - A google chrome extension. When you search only results from the past year (or set time period) are displayed. Helps tremendously when using new technologies to avoid outdated results.
User avatar
Kadanis
Forum Contributor
Posts: 180
Joined: Tue Jun 20, 2006 8:55 am
Location: Dorset, UK
Contact:

Post by Kadanis »

ok. cool.

thanks for the answers.

will have to broaden the bug search :)
Post Reply