MYSQL Connections

software development

#1

Hi,

Am using PHP-CGI (for security) + MYSQLI. Looking at my connection stats and am desperate to get them down, so I need a bit of help with this pretty please.

Don’t want to use PHP as an apache module as security is an issue and I’d have to recode.

I know that you can’t store the connection in a PHP SESSION var as connections are resources and resources can’t be stored that way.

I have written this connection function, please pick holes in it as much as you like!!! Can anyone suggestion anything better or any settings I could set to help out.

Many thanks in advance!!! The function sets a global var which holds the connection resources, but I am still getting a bad ration of connections/queries.

All help from PHP / MYSQL gurus is really really appreciated!

Here is this connect function:

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

global $connect;

if ( !( isset($connect) AND mysqli_ping($connect) ) ){
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 ;}