max_user_connections

    Date: 07/18/07 (PHP Community)    Keywords: php, mysql, database, sql

    I have a chronic problem with a fanfiction archive script I made. Since I've put it online, I hit max_user_connections in MySql very often, and my host is losing patience. The script opens a mySql connection (originally a normal one, now a permanent one by my host's suggestion) on loading and should use it for all the mysql calls forward. The archive is famous in the fandom and gets a lot of hits, but this shouldn't happen. I've tried to reduce the mysql calls at minimum, but I only get a few days reprieve. This is the code I use:

    In db_layer.php:

    function db_connect ($db_host, $db_user, $db_password, $db_database, $use_persistent = 0) {
    if ($use_persistent == 1) {
    $db_link = mysql_pconnect($db_host, $db_user, $db_password);
    } else {
    $db_link = mysql_connect($db_host, $db_user, $db_password);
    }

    if (!$db_link) {
    db_print_error("Unable to connect to SQL server", '');
    }

    $db_selected = mysql_select_db($db_database, $db_link);
    if (!$db_selected) {
    db_print_error("Unable to select database", '');
    }

    return $db_link;

    }

    Which is called at pagestart.php:
    $db_link = db_connect ($db_host, $db_user, $db_password, $db_database, 1);

    And querys are done this way:
    function db_query($query, $error_msg=0) {
    global $db_link;

    $result = mysql_query($query, $db_link);

    if ($result == false) {
    $error_msg = ($error_msg) ? $error_msg : "Error executing query";
    db_print_error($error_msg, $query);
    }

    return $result;
    }

    I am doing anything wrong? Does anyone have any advice for this problem, please? It's driving me crazy!

    Source: http://community.livejournal.com/php/576875.html

« html forms formatting || PHP5 Web Frameworks »


antivirus | apache | asp | blogging | browser | bugtracking | cms | crm | css | database | ebay | ecommerce | google | hosting | html | java | jsp | linux | microsoft | mysql | offshore | offshoring | oscommerce | php | postgresql | programming | rss | security | seo | shopping | software | spam | spyware | sql | technology | templates | tracker | virus | web | xml | yahoo | home