Damian Hupfeld
|
| Posted: 09/18/2005, 5:45 AM |
|
One of my hosting providers has set a frustratingly low max# of mysql
connections a single mysql user can have.
I get the following message -
Warning: mysql_pconnect(): User barana_web has already more than
'max_user_connections' active connections in
/home/itnext/public_html/bgroup/db_mysql.php on line 99
Database error: pconnect(localhost:3306, barana_web, $DBPassword) failed.
MySQL Error: 0 ()
Session halted.
Interestingly I have told CCS NOT to use Persistent connections and the
db_mysql.php indicates this as follows:
var $Persistent = false;
Anyways - on to the point of this post...
The common.php defines a class called dbProjectName which contains the
connection information as well as a stack of parameters to assist with the
connection.
I was wondering how I would split this class into 5 separate files with
slighly different connection info in each eg these two lines:
$this->DBUser = "user";
$this->DBPassword = "pass";
Set them as
$this->DBUser = "user1";
$this->DBPassword = "pass1";
and
$this->DBUser = "user2";
$this->DBPassword = "pass2";
etc
....and then I need to know how to randomly include just one of these files
into each page. This should extend the number of connections I can have to
the server....
Your help would be appreciated.
regards
Damian
class clsDBwebsitename extends DB_MySQL
{
var $DateFormat;
var $BooleanFormat;
var $LastSQL;
var $Errors;
var $RecordsCount;
var $RecordNumber;
var $PageSize;
var $AbsolutePage;
var $SQL = "";
var $Where = "";
var $Order = "";
var $Parameters;
var $wp;
function clsDBwebsitename()
{
$this->Initialize();
}
function Initialize()
{
$this->AbsolutePage = 0;
$this->PageSize = 0;
$this->DB = "MySQL";
$this->DBDatabase = "portal";
$this->DBHost = "localhost";
$this->DBPort = "3306";
$this->DBUser = "user";
$this->DBPassword = "pass";
$this->Persistent = true;
$this->RecordsCount = 0;
$this->RecordNumber = 0;
$this->DateFormat = Array("dd", "/", "mm", "/", "yyyy", " ", "HH",
":", "nn", ":", "ss");
$this->BooleanFormat = Array("true", "false", "");
$this->Uppercase = false;
$this->LastSQL = "";
$this->Errors = New clsErrors();
}
function MoveToPage($Page)
{
if($this->RecordNumber == 0 && $this->PageSize != 0 && $Page != 0)
if( !$this->seek(($Page-1) * $this->PageSize)) {
$this->Errors->addError("Cannot find specified record");
$this->RecordNumber = $this->Row;
} else {
$this->RecordNumber = ($Page-1) * $this->PageSize;
}
}
function PageCount()
{
return $this->PageSize ? ceil($this->RecordsCount / $this->PageSize)
: 1;
}
function ToSQL($Value, $ValueType)
{
if(($ValueType == ccsDate && is_array($Value)) || strlen($Value) ||
($ValueType == ccsBoolean && is_bool($Value)))
{
if($ValueType == ccsInteger || $ValueType == ccsFloat)
{
return doubleval(str_replace(",", ".", $Value));
}
else if($ValueType == ccsDate)
{
if (is_array($Value)) {
$Value = CCFormatDate($Value, $this->DateFormat);
}
return "'" . addslashes($Value) . "'";
}
else if($ValueType == ccsBoolean)
{
if(is_bool($Value))
$Value = CCFormatBoolean($Value, $this->BooleanFormat);
else if(is_numeric($Value))
$Value = intval($Value);
else
$Value = "'" . addslashes($Value) . "'";
return $Value;
}
else
{
return "'" . addslashes($Value) . "'";
}
}
else
{
return "NULL";
}
}
function SQLValue($Value, $ValueType)
{
if ($ValueType == ccsDate && is_array($Value)) {
$Value = CCFormatDate($Value, $this->DateFormat);
}
if(!strlen($Value))
{
return "";
}
else
{
if($ValueType == ccsInteger || $ValueType == ccsFloat)
{
return doubleval(str_replace(",", ".", $Value));
}
else if($ValueType == ccsBoolean)
{
if(is_bool($Value))
$Value = CCFormatBoolean($Value, $this->BooleanFormat);
else if(is_numeric($Value))
$Value = intval($Value);
else
$Value = addslashes($Value);
return $Value;
}
else
{
return addslashes($Value);
}
}
}
function query($SQL)
{
$this->LastSQL = $SQL;
return parent::query($SQL);
}
function OptimizeSQL($SQL)
{
$PageSize = (int) $this->PageSize;
if (!$PageSize) return $SQL;
$Page = $this->AbsolutePage ? (int) $this->AbsolutePage : 1;
$SQL .= " LIMIT " . (($Page - 1) * $PageSize) . "," .$PageSize;
return $SQL;
}
}
//End websitename Connection Class
|
|
|
 |
DonB
|
| Posted: 09/18/2005, 6:45 PM |
|
It appears like the persistent flag is getting set 'true' somewhere at
runtime. Either that or you've coded events that create new connection
objects and you don't unset() them. Or maybe you have 'too many' Record or
Grid controls, Listboxes or whatever on a page thus exceeding the limit of
your ISP.
I'd temporarily hardwire the 'if persistent' on or about line 98 in
my_sql.php to a 'false' and see if the problem goes away..
No way I'd attempt the manuever you are contemplating. I think it would be
more trouble than you already have. I don't know that it would actually
achieve the goal.
Lastly, I'd be looking for a better host if all else fails.
--
DonB
http://www.gotodon.com/ccbth
"Damian Hupfeld" <damian.hupfeld@itng.com.au> wrote in message
news:dgjnhd$q3b$1@news.codecharge.com...
> One of my hosting providers has set a frustratingly low max# of mysql
> connections a single mysql user can have.
>
> I get the following message -
>
> Warning: mysql_pconnect(): User barana_web has already more than
> 'max_user_connections' active connections in
> /home/itnext/public_html/bgroup/db_mysql.php on line 99
> Database error: pconnect(localhost:3306, barana_web, $DBPassword) failed.
> MySQL Error: 0 ()
> Session halted.
>
> Interestingly I have told CCS NOT to use Persistent connections and the
> db_mysql.php indicates this as follows:
> var $Persistent = false;
>
> Anyways - on to the point of this post...
>
> The common.php defines a class called dbProjectName which contains the
> connection information as well as a stack of parameters to assist with the
> connection.
>
> I was wondering how I would split this class into 5 separate files with
> slighly different connection info in each eg these two lines:
> $this->DBUser = "user";
> $this->DBPassword = "pass";
>
> Set them as
> $this->DBUser = "user1";
> $this->DBPassword = "pass1";
> and
> $this->DBUser = "user2";
> $this->DBPassword = "pass2";
> etc
>
> ...and then I need to know how to randomly include just one of these files
> into each page. This should extend the number of connections I can have to
> the server....
>
> Your help would be appreciated.
>
> regards
> Damian
>
>
>
> class clsDBwebsitename extends DB_MySQL
> {
>
> var $DateFormat;
> var $BooleanFormat;
> var $LastSQL;
> var $Errors;
>
> var $RecordsCount;
> var $RecordNumber;
> var $PageSize;
> var $AbsolutePage;
>
> var $SQL = "";
> var $Where = "";
> var $Order = "";
>
> var $Parameters;
> var $wp;
>
> function clsDBwebsitename()
> {
> $this->Initialize();
> }
>
> function Initialize()
> {
> $this->AbsolutePage = 0;
> $this->PageSize = 0;
> $this->DB = "MySQL";
> $this->DBDatabase = "portal";
> $this->DBHost = "localhost";
> $this->DBPort = "3306";
> $this->DBUser = "user";
> $this->DBPassword = "pass";
> $this->Persistent = true;
> $this->RecordsCount = 0;
> $this->RecordNumber = 0;
> $this->DateFormat = Array("dd", "/", "mm", "/", "yyyy", " ", "HH",
> ":", "nn", ":", "ss");
> $this->BooleanFormat = Array("true", "false", "");
> $this->Uppercase = false;
> $this->LastSQL = "";
> $this->Errors = New clsErrors();
> }
>
> function MoveToPage($Page)
> {
> if($this->RecordNumber == 0 && $this->PageSize != 0 && $Page != 0)
> if( !$this->seek(($Page-1) * $this->PageSize)) {
> $this->Errors->addError("Cannot find specified record");
> $this->RecordNumber = $this->Row;
> } else {
> $this->RecordNumber = ($Page-1) * $this->PageSize;
> }
> }
> function PageCount()
> {
> return $this->PageSize ? ceil($this->RecordsCount /
$this->PageSize)
> : 1;
> }
>
> function ToSQL($Value, $ValueType)
> {
> if(($ValueType == ccsDate && is_array($Value)) || strlen($Value)
||
> ($ValueType == ccsBoolean && is_bool($Value)))
> {
> if($ValueType == ccsInteger || $ValueType == ccsFloat)
> {
> return doubleval(str_replace(",", ".", $Value));
> }
> else if($ValueType == ccsDate)
> {
> if (is_array($Value)) {
> $Value = CCFormatDate($Value, $this->DateFormat);
> }
> return "'" . addslashes($Value) . "'";
> }
> else if($ValueType == ccsBoolean)
> {
> if(is_bool($Value))
> $Value = CCFormatBoolean($Value,
$this->BooleanFormat);
> else if(is_numeric($Value))
> $Value = intval($Value);
> else
> $Value = "'" . addslashes($Value) . "'";
> return $Value;
> }
> else
> {
> return "'" . addslashes($Value) . "'";
> }
> }
> else
> {
> return "NULL";
> }
> }
>
> function SQLValue($Value, $ValueType)
> {
> if ($ValueType == ccsDate && is_array($Value)) {
> $Value = CCFormatDate($Value, $this->DateFormat);
> }
> if(!strlen($Value))
> {
> return "";
> }
> else
> {
> if($ValueType == ccsInteger || $ValueType == ccsFloat)
> {
> return doubleval(str_replace(",", ".", $Value));
> }
> else if($ValueType == ccsBoolean)
> {
> if(is_bool($Value))
> $Value = CCFormatBoolean($Value,
$this->BooleanFormat);
> else if(is_numeric($Value))
> $Value = intval($Value);
> else
> $Value = addslashes($Value);
> return $Value;
> }
> else
> {
> return addslashes($Value);
> }
> }
> }
>
> function query($SQL)
> {
> $this->LastSQL = $SQL;
> return parent::query($SQL);
> }
>
> function OptimizeSQL($SQL)
> {
> $PageSize = (int) $this->PageSize;
> if (!$PageSize) return $SQL;
> $Page = $this->AbsolutePage ? (int) $this->AbsolutePage : 1;
> $SQL .= " LIMIT " . (($Page - 1) * $PageSize) . "," .$PageSize;
> return $SQL;
> }
>
> }
> //End websitename Connection Class
>
>
|
|
|
 |
2467
Posts: 47
|
| Posted: 10/03/2005, 3:43 AM |
|
My suggestion is to change this parameter:
$this->Persistent = true;
to
$this->Persistent = false;
You can do this way:
1. Right Click at your Database connection and select Edit
2. Select server
3. Uncheck Persistent Connection
After doing this everything will be ok
|
 |
 |
|