
Added by thebman220 on November-23-2008, 8:43 pm
<?php
/**
* @purpose : Creates/retrieves a mysqli object.
* Can also be used to create/retrieve
* a mysql resource. Uses, at most,
* two active connections (one for the
* object and one for the resource)
* @param boolean $override_error : If set to true, a string containing
* the mysql connection error is
* returned. You can use is_string()
* to test for such a return value.
* @param boolean $return_res : If set to true, a mysql resource
* will be returned, rather than a
* mysqli object.
* @param string $host : The MySQL host server
* @param string $username : The MySQL username
* @param string $password : The MySQL password (an empty string
* is equivilent to no password)
* @param string $database : The MySQL database
* @note : If $override_error is not set to
* true, any connection error is fatal.
* @note : If any of the last four parameters
* are omitted, this function will
* attempt to uses constants
* MYSQL_HOST, MYSQL_USERNAME,
* MYSQL_PASSWORD, and MYSQL_DATABASE
* to create the connection.
*/
function fetch_mysqli(
$override_error=false,
$return_res=false,
$host=MYSQL_HOST,
$username=MYSQL_USERNAME,
$password=MYSQL_PASSWORD,
$database=MYSQL_DATABASE
) {
if (!isset($globals["fetch_mysqli"])) {
$GLOBALS["fetch_mysqli"]=array();
}
$i="i";
if ($return_res) {
$i="";
if (isset($GLOBALS["fetch_mysqli"]["mysqli_res"])) {
return $GLOBALS["fetch_mysqli"]["mysqli_res"];
}
} else {
if (isset($GLOBALS["fetch_mysqli"]["mysqli"])) {
return $GLOBALS["fetch_mysqli"]["mysqli"];
}
}
$func="mysql{$i}_connect";
$mysqli=@$func($host,$username,$password,$database);
if (mysqli_connect_errno()) {
$error=mysqli_connect_error();
if ($override_error) {
return $error;
}
die("MySQL error: $error");
}
$GLOBALS["fetch_mysqli"]["mysqli".($return_res?"_res":"")]=$mysqli;
return $mysqli;
}
?>
Added by thebman220 on May-2-2009, 4:40 am
Added by thebman220 on April-29-2009, 11:47 pm
Added by thebman220 on April-5-2009, 1:48 pm
Added by thebman220 on January-29-2009, 3:15 am
Added by thebman220 on January-29-2009, 3:04 am