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 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56
   | <?php
 
class BD
{
	private $BD_Instance = null;
	private static $instance = null;
 
	private function __construct()
	{
		$this->BD_Instance = new PDO('mysql:dbname='.BD.';host='.HOST,USER,PASS);
	}
 
	public static function getInstance()
	{
		if(is_null(self::$instance))
		{
			self::$instance = new BD();
		}
		return self::$instance;
	}
 
	public function query($query)
	{
		return $this->BD_Instancee->query($query);
	}
 
	public function prepare($query)
	{
		return  $this->BD_Instance->prepare($query);
	}
 
	public function lire($query)
	{
		$test = $this->BD_Instance->prepare($query);
		$test->execute();
		return $test->fetchAll();
	}
 
	public function ecrire($query,$array)
	{
		$test = $this->BD_Instance->prepare($query);
		$test->execute($array);
		return $test->fetchAll();
	}
}
 
	const USER	= 'root';
	const HOST	= 'localhost';
	const PASS	= '';
	const BD	= 'test';
 
	$test = BD::getInstance()->lire('SELECT nom FROM categories');
	echo '<pre>', print_r($test) ,'</pre>';
 
 
	BD::getInstance()->ecrire("INSERT INTO categories(nom) VALUES(:test)",array(':test'=>'Un autre tupple!')); | 
Partager