Merhaba Arkadaşlar,
Sizler için ufak birşey hazırladım kullanımı basit olur CLASS kodlama yapan arkadaşlara güzel bir class olacağını düşünüyorum…
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 |
<?php header("Content-type: text/html; charset=utf-8"); class DB { protected $conn = false; private $server, $user, $password, $db; public function __construct($server, $user, $password, $db){ $this->server = $server; $this->user = $user; $this->password = $password; $this->db = $db; $this->open(); } public function open(){ $this->conn = mysql_connect($this->server, $this->user, $this->password); if(!$this->conn){ echo "MySQL ile Bağlantı Kurulamadı!.."; return false; } $this->db = mysql_select_db($this->db, $this->conn); if(!$this->db){ echo "Veritabanı ile Bağlantı Kurulamadı!.."; return false; } } public function __sleep(){ mysql_close($this->conn); $this->conn = false; return array('server', 'user', 'password', 'db'); } public function __wakeup(){ $this->open(); } public function __desctruct(){ if($this->conn){ mysql_close($this->conn); $this->conn = null; } } } $db = new DB('localhost', 'db_isim', 'db_şifre', 'db_adi'); ?> |