PHP/MYSQLI Persistent connections

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • jonndoe45
    New Member
    • Oct 2006
    • 3

    #1

    PHP/MYSQLI Persistent connections

    Hi,

    Am using PHP-CGO, MYSQL and am having to connect to the MYSQL server every time that a query is run.

    I wrote this connection function (below) in a vain attempt to try and limit the number of connections, but doesn't seem to help.

    I know you can't store the connection resource in a session var as resources cant be stored in session vars.

    Does anyone have any ideas ? code ? tricks or settings that they can please advise me with, many thanks in advance.

    Heres the code:


    ############### ############### ############### ############### ############### #####
    function con1(){
    ############### ############### ############### ############### ############### #####

    global $connect;

    if ( !( isset($connect) AND mysqli_ping($co nnect) ) ){
    if ( local() ) {
    $host = "localhost" ;
    $account = unhex("blah", _HASH_KEY, _HASH_CYPHER, _HASH_IV);
    $password = unhex("blah", _HASH_KEY, _HASH_CYPHER, _HASH_IV);
    $dbname = "blah";}
    else {
    $host = "blah";
    $account = unhex("blah", _HASH_KEY2, _HASH_CYPHER, _HASH_IV2);
    $password = unhex("blah", _HASH_KEY2, _HASH_CYPHER, _HASH_IV2);
    $dbname = "blah";}
    $connect = mysqli_connect( $host,$account, $password, $dbname);

    if (mysqli_connect _errno()) {
    printf("Connect failed: %s\n", mysqli_connect_ error());
    die();}
    }

    return ;}
Working...