Open only one DB connection per PHP call
This commit is contained in:
parent
e270333055
commit
7fc7a002e3
6 changed files with 34 additions and 84 deletions
|
|
@ -11,7 +11,7 @@ class Theme
|
|||
{
|
||||
if (!empty($id))
|
||||
{
|
||||
$db = new BDD();
|
||||
global $db;
|
||||
$res = $db->unique_query("SELECT `id`, `name`
|
||||
FROM themes WHERE id=" . intval($id));
|
||||
|
||||
|
|
@ -21,11 +21,7 @@ class Theme
|
|||
$this->name = $res['name'];
|
||||
}
|
||||
else
|
||||
{
|
||||
$db->deconnexion();
|
||||
throw new ThemeNotFoundException();
|
||||
}
|
||||
$db->deconnexion();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -43,7 +39,7 @@ class Theme
|
|||
{
|
||||
$name = $this->name;
|
||||
|
||||
$db = new BDD();
|
||||
global $db;
|
||||
$db->escape($name);
|
||||
|
||||
if (empty($this->id))
|
||||
|
|
@ -60,7 +56,6 @@ class Theme
|
|||
WHERE id = ".intval($this->id));
|
||||
$aff = $db->affected();
|
||||
}
|
||||
$db->deconnexion();
|
||||
|
||||
Cache::del("ordered_th".$this->id);
|
||||
|
||||
|
|
@ -84,11 +79,10 @@ class Theme
|
|||
|
||||
function get_nb_exercices()
|
||||
{
|
||||
$db = new BDD();
|
||||
global $db;
|
||||
$res = $db->unique_query("SELECT count(id) as nb_exercices FROM exercices
|
||||
WHERE id_theme = ".$this->id."
|
||||
GROUP BY id_theme");
|
||||
$db->deconnexion();
|
||||
|
||||
return $res['nb_exercices'];
|
||||
}
|
||||
|
|
@ -109,13 +103,11 @@ class Theme
|
|||
if (!empty($res))
|
||||
return $res;
|
||||
|
||||
$db = new BDD();
|
||||
global $db;
|
||||
$res = $db->query("SELECT E.id, E.require FROM exercices E
|
||||
INNER JOIN themes T ON T.id = E.id_theme
|
||||
WHERE T.id = ".intval($this->id));
|
||||
|
||||
$db->deconnexion();
|
||||
|
||||
$size = count($res);
|
||||
|
||||
for ($i = 0; $i < $size; $i++)
|
||||
|
|
@ -152,9 +144,8 @@ class Theme
|
|||
|
||||
public static function get_themes()
|
||||
{
|
||||
$db = new BDD();
|
||||
global $db;
|
||||
$ids = $db->query("SELECT `id` FROM `themes` ORDER BY `name`");
|
||||
$db->deconnexion();
|
||||
|
||||
$array = array();
|
||||
if ($ids)
|
||||
|
|
@ -168,4 +159,3 @@ class Theme
|
|||
class ThemeNotFoundException extends Exception
|
||||
{
|
||||
}
|
||||
|
||||
|
|
|
|||
Reference in a new issue