/** * Конструктор */ public function __construct() { //Получаем имя драйвера $db = Boot::getInstance()->config->db; $driver = $db->adapter; $host = $db->host; $port = $db->port; $user = $db->user; $pass = $db->password; $dbase = $db->dbase; //Инитим драйвер $this->_db = new $driver($host, $port, $user, $pass, $dbase); //Подключаемся к базе $this->_db->connect(); }
/** * Добавить строку в таблицу * @param array $data * @return int */ public function insert(array $data) { $id = $this->_db->insert($this->table, $data, $this->pkey); // if( $id == false ) { // throw new DB_Exeption("Error insert value"); // } return $id; }
/** * Добавление join к запросу * @param string $table * @param string|array|null $on * @throws DB_Exception */ public function joins($table, $on = null) { //Если указано кол-во таблиц больше 1, то хз че делать if (count($this->_table) > 1) { throw new DB_Exception("Must be table count 1"); } //Добавочное условие if ($on === null) { $where = null; } else { $where = " AND " . $this->make_where($table, $on); } //Добавляем $this->_joins .= " INNER JOIN " . $this->driver->escape_identifier($table) . " ON " . $this->driver->escape_identifier($table) . "." . $this->driver->escape_identifier($this->_table[0] . "_id") . " = " . $this->driver->escape_identifier($this->_table[0]) . "." . $this->driver->escape_identifier("id") . $where; }
<?php // INCLUDE DE LA PÁGINA DE LA CLASE CONNECT require_once "class/connect/postgres.php"; // Crear la instancia del objeto. global $Base; $Base = new postgres(); //$Base->host="192.168.1.7"; $Base->host = "192.168.53.1"; $Base->database = "dteconfiguracion"; $Base->user = "******"; $Base->password = "******"; $Base->conn = $Base->db_connect() or die("No fue posible connectar con la base de dados -> " . "{$Base->database}"); if ($uf == 0) { echo "envía email"; } else { $sql = "insert into valoresmonedas(fecha,uf,dolarob,dolaracu,utm,euro)values(now(),{$uf},{$dolaeobs},0,{$utm},{$euro})"; $Base->query($sql) or die($sql); }