Multiple Database Users Fix max_questions Problem wp-cofig.php JQuery limit (2 posts)

  1. vitalvintage
    Posted 3 years ago #

    Ok, so my HOST has a JQueery limit or max_questions limit or throtles it at 75,000. which im sure all of you out there on a shared host have some sort of limit like me. I only noticed this problem when trying to import 1,000s of products through P. CSV import suite. And of course no one really wants to help you. So.....I found the following code to slightly help by randomizing multiple users and droping the number of importing products to 250 at a time. It still hits an overloaded user once in a while but i able no to upload on avg 1000 products an hour. where before, with one user i could only upload a couple hundred an hour. Here is my present code:

    // ** MySQL settings - You can get this info from your web host ** //
    /** The name of the database for WordPress */
    define('DB_NAME', 'myDATAbaseNAME');

    /** MySQL database username */
    $auser = array( 'user1', 'user2', 'user3', 'user4', 'user5', 'user6', 'user7', 'user8', 'user9');
    $user = $auser[ rand(0,5) ];
    define('DB_USER', $user); // Your MySQL username

    /** MySQL database password */
    define('DB_PASSWORD', 'MYpasswordHERE');

    /** MySQL hostname */
    define('DB_HOST', 'myhostingaccountname.HOSTmysql.com');

    /** Database Charset to use in creating database tables. */
    define('DB_CHARSET', 'utf8');

    /** The Database Collate type. Don't change this if in doubt. */
    define('DB_COLLATE', '');
    Now, I found the following php code which as state should:
    " This should try every name until it can connect - thus (in theory) exponentially adding available mysql resources your database is alotted."
    Here is the code:

    function dbConnector(){
    $aUser = array("userOne","userTwo","userThree");
    $aPass = array("passOne","passTwo","passThree");
    for($i=0; $i<sizeof($aUser); $i++){
    if(!($oConn = mysql_connect("whatever.powweb.com",$aUser[$i],$aPass[$i]))){
    $errorlist .= mysql_error()."
    if(!($oConn = mysql_connect("localhost",$aUser[$i],$aPass[$i]))){
    $errorlist .= mysql_error()."
    return $oConn;
    return $oConn;
    //sample of a connection call...
    //once you've connected and it gives you an object,
    //treat it like you would any other MySQL connection object.
    $mysql_connection_object = dbConnector();
    //do your queries or whatever you want like usual
    What I would like is for someone to rewrite the second code above to work in word press. To replace my existing random code in the wp-config.php file. I believe this will solve many peoples problems!!! Please some rewrite this code to work! Thanks!

  2. schulz
    Posted 3 years ago #

    I have a web host that set the user database connection limit way low causing 'unable to connect to database' errors. This is what I used to hopefully overcome this problem, however this was not tested extensively (use at your own risk).

    In the wp-config.php file replace lines:

    /** MySQL database username */
    define('DB_USER', 'wpdbusername');

    /** MySQL database password */
    define('DB_PASSWORD', 'wpdbpassword');

    with the code below:

    /* MySQL database connection limit fail-over *\
    \* By Wayne D Schulz (CC BY-SA) 2013/04/19 */

    $aUser = array( 'user1', 'user2', 'user3', 'user4', 'user5', 'user6', 'user7', 'user8', 'user9' );
    $aPass = array( 'pass1', 'pass2', 'pass3', 'pass4', 'pass5', 'pass6', 'pass7', 'pass8', 'pass9' );

    for($i=0; $i<sizeof($aUser); $i++) {
    $dbLink = mysql_connect("localhost",$aUser[$i],$aPass[$i]);
    if (!$dbLink) {
    $errorlist .= date("D M j G:i:s T Y", time())." - ".mysql_error()."\r\n";
    error_log($errorlist, 3, "/var/tmp/connect-errors.log");
    $dbUser = $aUser[$i];
    $dbPass = $aPass[$i];

    /* last dbUser and dbPass */
    if (!isset($dbUser)) { $dbUser = "user10"; }
    if (!isset($dbPass)) { $dbPass = "pass10"; }

    /** MySQL database username */
    define('DB_USER', $dbUser);

    /** MySQL database password */
    define('DB_PASSWORD', $dbPass);

Topic Closed

This topic has been closed to new replies.

About this Topic