Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- error_reporting(E_ALL);
- class PDODO
- {
- protected $table_name;
- private $db;
- /**
- *
- * @Connect to the database and set the error mode to Exception
- *
- * @Throws PDOException on failure
- *
- */
- public function conn()
- {
- if (!$this->db instanceof PDO)
- {
- $this->db = new PDO($this->dsn, $this->username, $this->password);
- $this->db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
- }
- }
- /**
- *
- * The constructor each derived class should have
- * its own constructor containing proper values
- *
- */
- function __construct()
- {
- $this->dsn = "mysql:dbname=test;host=localhost";
- $this->username = 'username';
- $this->password = 'password';
- $this->table_name = get_called_class();
- }
- /**
- * settor
- *
- * @access public
- *
- * @param string $name
- *
- * @param string $value
- *
- */
- public function __set($name, $value)
- {
- switch($name)
- {
- case 'dsn':
- $this->dsn = $value;
- break;
- case 'username':
- $this->username = $value;
- break;
- case 'password':
- $this->password = $value;
- break;
- case 'field_list':
- if(is_array($value))
- {
- $this->field_list = $value;
- }
- break;
- case 'primary_key':
- $this->primary_key = $value;
- break;
- default:
- throw new Exception ("Uable to set $name");
- }
- }
- public function select($id=null)
- {
- }
- public function insert($values)
- {
- }
- public function update($id, $values)
- {
- }
- } // end of class
- /**
- *
- * @class name is named the same as the db table
- *
- */
- class cars extends PDODO
- {
- protected $car_id, $car_cost, $car_price, $car_description;
- } // end class
- $cars = new cars;
- $cars->select(3);
- ?>
Add Comment
Please, Sign In to add comment