Example #1
0
 /**
  * Initializes database connection
  *
  * @param $pixie
  * @param string $config Name of the connection to initialize
  * @return \PHPixie\DB\PDOV\Connection
  */
 public function __construct($pixie, $config)
 {
     parent::__construct($pixie, $config);
     $this->conn = new \PDO($pixie->config->get("db.{$config}.connection"), $pixie->config->get("db.{$config}.user", ''), $pixie->config->get("db.{$config}.password", ''));
     $this->conn->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
     $this->db_type = strtolower(str_replace('PDO_', '', $this->conn->getAttribute(\PDO::ATTR_DRIVER_NAME)));
     if ($this->db_type != 'sqlite') {
         $this->conn->exec("SET NAMES utf8");
     }
 }
 /**
  * Saves the item back to the database. If item is loaded() it will result
  * in an update, otherwise a new row will be inserted
  *
  * @return \PHPixie\ORM\Model Returns self
  */
 public function save()
 {
     if ($this->loaded()) {
         $query = $this->conn->query('update')->table($this->table)->where($this->id_field, $this->_row[$this->id_field]);
     } else {
         $query = $this->conn->query('insert')->table($this->table);
     }
     $query->data($this->_row);
     $query->execute();
     if ($this->loaded()) {
         $id = $this->_row[$this->id_field];
     } else {
         $id = $this->conn->insert_id();
     }
     $row = (array) $this->conn->query('select')->table($this->table)->where($this->id_field, $id)->execute()->current();
     $this->values($row, true);
     return $this;
 }
Example #3
0
 /**
  * Initializes database connection
  *
  * @param string $config Name of the connection to initialize
  * @return void
  */
 public function __construct($pixie, $config)
 {
     parent::__construct($pixie, $config);
     $this->conn = mysqli_connect($pixie->config->get("db.{$config}.host", 'localhost'), $pixie->config->get("db.{$config}.user", ''), $pixie->config->get("db.{$config}.password", ''), $pixie->config->get("db.{$config}.db"));
     $this->conn->set_charset("utf8");
 }