PDA

View Full Version : Randomize Database User Connections


skidpics
September 25th, 2009, 12:58 PM
Until I get a dedicated server, I am only allowed 50 MySQL connections - per database users.

I can get around that, as suggested my my hosting support, to add more database users, and randomly connect to the DB with those different users.

Would anyone know how to randomize the connection process, for more users?

Chuck S
September 25th, 2009, 08:28 PM
That would definately take a good deal of rewriting of the entire $link section here. As to what would need to be changed I have never personally looked at it.


if ( VB35 == "on" )
{
// vB3.5 forces us to reverse the call method to conform to their new connect code
$link = mysql_connect("$host", "$mysql_user", "$mysql_password") or die ('I cannot connect to the PhotoPost database. [$php_errormsg]');
mysql_select_db ("$database", $link)or die("Could not connect to PhotoPost database". mysql_error() );

if ( $host == $host_bb && $database == $database_bb && $mysql_user == $user_bb )
{
$db_link = $link;
}
else
{
$db_link = mysql_connect("$host_bb:3306", "$user_bb", "$password_bb") or die ("I cannot connect to the Members database. [$php_errormsg]");
mysql_select_db("$database_bb", $db_link)or die("Could not connect to User database". mysql_error() );
}
}
else
{
$link = mysql_connect("$host:3306", "$mysql_user", "$mysql_password") or die ('I cannot connect to the PhotoPost database. [$php_errormsg]');
mysql_select_db ("$database", $link)or die("Could not connect to PhotoPost database". mysql_error() );

if ( $host == $host_bb && $database == $database_bb && $mysql_user == $user_bb )
{
$db_link = $link;
}
else
{
$db_link = mysql_connect("$host_bb", "$user_bb", "$password_bb") or die ("I cannot connect to the Members database. [$php_errormsg]");
mysql_select_db("$database_bb", $db_link)or die("Could not connect to User database". mysql_error() );
}
}

skidpics
September 26th, 2009, 01:27 AM
Not for VB - just basic PP Pro

Chuck S
September 26th, 2009, 07:38 AM
Right I am merely stating anything you do or code up would probally be centered around there as thats where we define the $link and $db_link lines.

skidpics
September 27th, 2009, 01:12 AM
Right I am merely stating anything you do or code up would probally be centered around there as thats where we define the $link and $db_link lines.

I basically need something like this:

$mysql_user1="vande11_user1";
$mysql_user2="vande11_user2";
$mysql_user3="vande11_user3;

$random_user = $mysql_user1, $mysql_user1, $mysql_user1

$mysql_user= $random_user

I am guessing this should work for each login.. as it will randomly select a differnet users based on the $random_user

skidpics
September 27th, 2009, 01:26 AM
I this should work..

$the_dbarray = array( "user1", "user2", "user3", "user3" ); //<--Note the extra "item3"
shuffle($the_dbarray);

$mysql_user = $the_dbarray

This should select 1 of the users# for a database connection, then pass the results to $mysql_user. Testing it, it is working. I would figure if there was an error, I would not be able to login ;-)

If only now I can base the random of Max_Sql connections, then it would work perfect.. for shared hosting, at this point in time.

Chuck S
September 27th, 2009, 07:32 AM
yeah thats probally a very basic way to do it for your situation if your mysql password is the same for all users sure.

skidpics
September 27th, 2009, 09:57 AM
yeah thats probally a very basic way to do it for your situation if your mysql password is the same for all users sure.

True.

It would be nice the make it more of an

if .. else kinda thing, where it checks connections maxed out or not. I will keep looking for code snippets that will help me until such time as I move to a dedicated server. thanks..

Chuck S
September 27th, 2009, 01:34 PM
yeah well if your host limits mysql connections to 50 per user sounds to me like you need a better host as thats even way more restrictive than powweb which I think is like 50000.

skidpics
September 27th, 2009, 06:21 PM
You are right. I am on shared housting though - for now..

Bluehost has some good options, so I am in touch with them.. Powweb I haven't checked out yet - but will look into it.

Chuck S
September 27th, 2009, 06:28 PM
No you dont want powweb.

Check out my host westhost.com

skidpics
September 27th, 2009, 06:41 PM
What's wrong with PowWeb?

Unlimited Space/ Unlimited data

skidpics
September 27th, 2009, 06:47 PM
well, Bluehost is out - 60 only and only shared hosting.

skidpics
September 27th, 2009, 06:50 PM
well, the randomizing of users for the DB seemed to solve my problem 4 now...

Chuck S
September 27th, 2009, 07:20 PM
Thats a good thing.