L'nstanciation de mon objet ne fonctionne pas
Bonsoir,
J'ai une classe de connexion à ma BD :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40
| <?php
class DB extends PDO
{
private static $_instance = null;
private static $_port = '8889';
private static $_host = 'localhost';
private static $_user = 'root';
private static $_password = 'root';
protected static $_dbname;
public static function getInstance($dbname = 'imaginatiff')
{
if (is_null(self::$_instance))
{
try
{
self::$_instance = new PDO('mysql:host='.self::$_host.';port='.self::$_port.';dbname='.self::$_dbname, self::$_user, self::$_password);
self::$_instance->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (PDOException $e)
{
throw new Exception('Connection failed or database cannot be selected : ' . $e->getMessage());
}
self::$_instance = new self();
}
return self::$_instance;
}
public function __construct()
{
}
private function __clone () { }
public function __destruct()
{
self::$_instance = null;
}
}
?> |
Quand j'instancie un objet de type BD :
Code:
1 2 3 4 5 6
| <?php
//inclut l'auto-loader.
require("auto_loader/auto_loader.php");
$db = DB::getInstance(); |
j'obtiens ceci :
Citation:
object(DB)#3 (0)
{
}
Je présume que mon objet n'a pas été créé ?
Je débute avec la POO, sauriez-vous me dire comment je peux débuger afin de savoir où se trouve le problème svp ?
Merci d'avance.
bee