Example #1
0
 function __construct($table)
 {
     if (!isset(self::$DB)) {
         //self::$DB = new PDO('mysql:dbname=mapper;host=localhost', 'mapper', 'mapper' );
         self::$DB = api_database::factory();
         self::$DB->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
         self::$DB->setAttribute(PDO::ATTR_CASE, PDO::CASE_NATURAL);
         self::$logger = api_log::getInstance();
     }
     //echo "<br />self::DB => ";
     //$sth = self::$DB->exec("select * from user");
     //print_r(self::$DB->errorCode());
     //echo "<br />";
     $this->driver = self::$DB->getAttribute(PDO::ATTR_DRIVER_NAME);
     $this->table = $table;
     switch ($this->driver) {
         case 'mysql':
             $this->name_opening = $this->name_closing = '`';
             break;
         case 'mssql':
             $this->name_opening = '[';
             $this->name_closing = ']';
             break;
         case 'pgsql':
             $this->name_opening = "'";
             $this->name_closing = "'";
             $this->column_opening = $this->column_closing = '"';
             break;
         default:
             $this->name_opening = $this->name_closing = '"';
             break;
     }
     $this->table_meta = $this->get_table_meta();
     $this->table_meta_minus_pk = $this->table_meta;
     unset($this->table_meta_minus_pk[$this->primary_key]);
     $this->selectStmt = "SELECT * FROM " . $this->table . " WHERE {$this->primary_key}=?";
     $this->selectAllStmt = "SELECT * FROM {$this->table}";
     //     $this->updateStmt           = $this->buildUpdateStmt();
     $this->insertStmt = $this->buildInsertStmt();
     $this->deleteStmt = "DELETE FROM {$this->table} WHERE id = ?";
     // }
     foreach ($this->table_meta as $key => $value) {
         $this->{$key} = '';
     }
 }
Example #2
0
 function __construct()
 {
     parent::__construct($this->table);
 }