napisalem sobie prostą klasę do obsługi MySQL, nie zamieszczam tego jeszcze w dziale oceny ponieważ to nic wielkiego, chciałbym jeszcze nad nią tochę popracować, co radzicie, przeglądałem troche kody podobnych klas, czekam na Wasze opinie
myślę o jakiejś obsłudze błędów ponieważ narazie nie ma to żadnych zabezpieczeń
pzdr
<? //show_source ('mysql.class.php'); private $host; private $user; private $password; private $database; public $id_connection; public function __construct ($host, $user, $password, $database) { $this->host = $host; $this->user = $user; $this->password = $password; $this->database = $database; throw new Exception ('Nie mogę połączyć się z serwerem bazy danych'); } throw new Exception ('Nie mogę połączyć się bazą danych: '.$this->database); } } public function make_query($sql) { } public function __destruct () { } } class mysql_res implements IteratorAggregate { private $result; public function __construct($result) { $this->result = $result; } public function getIterator() { return new mysql_res_iterator($this->result); } } class mysql_res_iterator implements Iterator { private $result; private $current = 0; private $rows; public function __construct($result) { $this->result = $result; } } return $this->current; } $this->current = 0; } $this->current++; } public function valid() { return $this->current < $this->rows; } } ?>
i użycie:
<? function __autoload($classname) { include_once $classname.'.class.php'; } try { $sql = 'SELECT * FROM ks_tel'; $dane = $db->make_query($sql); foreach ($dane as $id ){ } } catch (Exception $e) { } ?>