Re: Reusing MySQL Connections - Can it be done?

From: Date: Mon, 05 Apr 2004 23:12:35 +0000
Subject: Re: Reusing MySQL Connections - Can it be done?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-182422@lists.php.net to get a copy of this message
Monday, April 5, 2004, 11:23:29 PM, you wrote: > I am trying to use fewer resources and processes when making database > connections in my scripts, so, upon the first call to make a DB connection, > I store the Link Resource ID in a constant variable that can be accessed by > all other functions that need a DB connection, like this... > function connect_db() { > if (!defined('_CONNECT_DB')) { > $result = @mysql_pconnect("localhost", "Username", > "Password"); > @mysql_select_db("database_name"); > define('_CONNECT_DB', $result); > } > return _CONNECT_DB; <snipped> From: http://www.php.net/manual/en/language.constants.php Only scalar data (boolean, integer, float and string) can be contained in constants. ---------- somewhere in the manual it is said that while a resource or link or some such identifier might look like an integer, it actually isn't. So by extension it is not a scalar value and thus cannot be stored via the means of a define(). Use a 'normal' variable instead. Richard

« previous php.general (#182422) next »