示例#1
0
 private function getVersion()
 {
     $db = api_database::factory();
     if ($stmt = $db->query("SELECT * FROM schema_migrations order by version DESC")) {
         $v = $stmt->fetch(PDO::FETCH_ASSOC);
     } else {
         $db->query("CREATE TABLE schema_migrations (version character(14))");
         $v['version'] = 0;
     }
     return $v['version'];
 }
示例#2
0
 /**
  * Constructor.
  */
 public function __construct()
 {
     //parent::__construct($opts);
     // TODO Shold session management be handled this way?
     $sessionid = session_id();
     if (empty($sessionid)) {
         session_start();
     }
     $this->config = api_config::getInstance();
     $this->request = api_request::getInstance();
     $this->db = api_database::factory();
 }
示例#3
0
 function __construct()
 {
     //$this->db = new Database("mysql:host=localhost;dbname=mapper", "mapper", "mapper");
     //echo "\nCalling api_database::factory()\n";
     $this->db = api_database::factory();
     //echo "\nIn commands_migration_migrations - constructor\n";
     //print_r( $this->db );
     $this->platform = "mysql";
     // get database config
     $this->config = api_config::getInstance()->database;
     $this->config = $this->config['default'];
     //print_r($this->config);
 }
示例#4
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} = '';
     }
 }
示例#5
0
 function openid_provider_rp_save($uuid, $realm, $auto_release = FALSE)
 {
     // TODO
     /*$rpid = db_result(db_query("SELECT rpid FROM {openid_provider_relying_party} WHERE uid=%d AND realm='%s'", $uid, $realm));
       if ($rpid) {
         db_query("UPDATE {openid_provider_relying_party} SET auto_release=%d, last_time=%d WHERE rpid=%d", $auto_release, time(), $rpid);  
          */
     $db = api_database::factory();
     $stmt = $db->prepare("SELECT * FROM relying_partties WHERE uuid = ? AND realm = ?");
     $stmt->execute(array($uuid, $realm));
     $result = $stmt->fetch(PDO::FETCH_OBJ);
     if (!empty($result)) {
         echo "Update";
         $db->exec("UPDATE relying_parties SET auto_release={$auto_release}, lasttime=" . time() . " where id = " . $result->id);
     } else {
         echo "insert";
         $auto_release = true;
         $db->exec("insert into relying_parties (uuid, realm, firsttime, lasttime, auto_release) VALUES ({$uuid}, '{$realm}', '" . time() . "', '" . time() . "', {$auto_release})");
         print_r($db->errorInfo());
         //db_query("INSERT INTO {openid_provider_relying_party} (uid, realm, first_time, last_time, auto_release) VALUES (%d, '%s', %d, %d, %d)", $uid, $realm, time(), time(), $auto_release);
     }
 }