Re: mysql persistent connections / php4
| From: | Patrik Wallstrom | Date: | Fri, 11 Aug 2000 14:16:19 +0000 |
| Subject: | Re: mysql persistent connections / php4 | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-11324@lists.php.net to get a copy of this message | ||
On Fri, 11 Aug 2000, Brendan W. McAdams wrote:
> MYSQL_SELECT_DB is neither smart nor persistant.
> If your code calls SELECT_DB, mysql executes it.
>
> I actually use persistant connections on a server handling ~40 mysql enabled
> clients.
> It increases my performance to have all of my MySQL connections cached, so
> all each customer query needs is a change db, make query.
I am using a function like this for most of my queries:
function dbQuery($sql, $db = DB, $errorMessage = "Unspecified database error",$connection
= FALSE) {
if(!$connection){
$connection = dbConnect(); //Try to find a connection if not connection given
}
if ($connection == FALSE) {
sxError(SX_ERROR_DB,"db connection in dbQuery");
}
$query = mysql_db_query($db, $sql, $connection);
if (!$query) {
if($errorMessage) {
sxError(SX_ERROR_QUERY, $errorMessage."<br>\n". "Query: $sql
<br>\n" . mysql_error()); //."<br>SQL: $sql<br>Mysql error:
".mysql_error()."<br>");
} else
return false;
}
return($query);
}
and dbConnect looks like this:
function dbConnect() {
$user = "blabla";
$pass = "yadayada";
$server="bar.foo.com";
if (!$connection = mysql_pconnect(@$server, @$user, @$pass)){
die("Cannot connect to database!");
}
return $connection;
}
Any ideas?
--
patrik wallstrom | f o o d f i g h t
tel: +46-8-6188428 | s t o c k h o l m
gsm: +46-708405080 | - - - - - - - - -
fax: +46-859827151 |