У меня есть сайт, который получает всего около 100 человек каждый день, но я получил сообщение об ошибке при входе в систему как пользователь:Database Error
Warning: mysqli::mysqli() [mysqli.mysqli]: (42000/1203): User mexautos_Juan already has more than 'max_user_connections' active connections in /home/mexautos/public_html/kiubbo/data/model.php on line 26
Warning: mysqli::query() [mysqli.query]: Couldn't fetch mysqli in /home/mexautos/public_html/kiubbo/data/model.php on line 87
Query failed
Я обновить страницу несколько раз, и теперь его хорошо, но так как у меня не так много пользователей, я подозреваю, что это ошибка в моем коде, где я должен искать его?
Thx
Edit: это модель файла:
<?php
/*
Model is the base class from which the other
model classes will be derived. It offers basic
functionality to access databases
*/
require_once($_SERVER['DOCUMENT_ROOT'].'/config.php');
require_once(SITE_ROOT.'includes/exceptions.php');
class Model {
private $created;
private $modified;
static function getConnection()
{
/*
Connect to the database and return a
connection or null on failure
*/
$db = new mysqli (DB_HOST, DB_USER, DB_PASS, DB_NAME);
if(!$db) {
echo mysql_error();
throw new Exception('Could not connect to database', EX_NO_DATABASE_CONNECTION);
}
return $db;
}
static function execSQL($query)
{
/*
Execute a SQL query on the database
passing the tablename and the sql query.
Returns the resultset
*/
$db = null;
$results = null;
//echo "query is $query";
try
{
$db = Model::getConnection();
$results = $db->query($query);
if(!$results) {
throw new Exception('Query failed', EX_QUERY_FAILED);
}
}
catch(Exception $e)
{
/* errors are handled higher in the
object hierarchy
*/
throw $e;
}
Model::closeConnection($db);
return $results;
}
static function execSQl2($query)
{
/*
Execute a SQL query on the database
passing the tablename and the sql query.
Returns the LAST_INSERT_ID
*/
$db = null;
$lastid = null;
//echo "query is $query";
try
{
$db = Model::getConnection();
$results = $db->query($query);
if(!$results) {
throw new Exception('Query failed', EX_QUERY_FAILED);
}
$lastid = $db->insert_id;
}
catch(Exception $e)
{
/* errors are handled higher in the
object hierarchy
*/
throw $e;
}
Model::closeConnection($db);
return $lastid;
}
function delete($table, $id, $conditions = '')
{
$query = "delete from $table where id = $id";
try
{
$db = Model::getConnection();
$results = Model::execSQL($query);
if(!$results){
throw new Exception('Could not delete this object', EX_DELETE_ERROR);
}
return $results->num_rows;
}
catch(Exception $e)
{
throw $e;
}
}
static function closeConnection($db)
{
$db->close();
}
function getCreated()
{
return $this->created;
}
function setCreated($value)
{
$this->created = $value;
}
function getModified()
{
return $this->modified;
}
function setModified($value)
{
$this->modified = $value;
}
}
?>
Спасибо, так что я должен делать то же самое, что и с $ db? создать другую функцию с помощью: $ results-> close(); ? – jcslzr
Честно говоря, я не уверен. Я удалил свой комментарий, потому что это что-то вроде моей глубины. Но если вы просмотрите документацию для mysqli, вы заметите, что это сильно означает, что набор результатов запроса - это буферизованное соединение с базой данных. Хотя кажется, что $ db-> close() завершит соединение, в документации для запроса указывается, что он использует соединение с базой данных для получения результатов. – GoingTharn
Спасибо, я посмотрю. – jcslzr