/ Published in: PHP
Expand |
Embed | Plain Text
Copy this code and paste it in your HTML
<?php class Conexao { private $host = DB_SERVER; private $dbname = DB_NAME; private $user = DB_USER; private $pswd = DB_PASS; private $port = DB_PORT; var $_query_id; private $con; public function __construct() { $this->con = pg_connect("host=$this->host dbname=$this->dbname user=$this->user password=$this->pswd port=$this->port"); if (!$this->con) { } } //método construtor public function fecha(){ # fecha cpnexão } public function execute($sql) { $retorno = false; # executa a query //print_r($sql); # no caso de select, os dados são colocados em um array $retorno = $result; else { while ($row = $this->fetch_assoc($result)) { # codifica resultado para utf8 $retorno[] = $row; } } } /** * Metodo que irá criar um Array com os dados da consulta. * @param {string} $result: Resultado da Consulta. * @return {array} $rows: Array com os dados da Consulta. **/ function criarArray($result = ''){ $result = !$result ? $this->_queryId : $result; // LOOP que irá criar o Array com os dados. while ($row = $this->fetch_object()) { # codifica resultado para utf8 $rows[] = $row; } return $rows; } public function sqlQuery($sql) { return $this->_query_id ? $this->_query_id : false; } public function insert_id() { } public function fetch_array($query_id = '') { $query_id = (!$query_id) ? $this->_query_id : $query_id; } public function fetch_row($query_id = '') { $query_id = (!$query_id) ? $this->_query_id : $query_id; } public function fetch_object($query_id = '') { $query_id = (!$query_id) ? $this->_query_id : $query_id; } public function fetch_assoc($query_id = '') { $query_id = (!$query_id) ? $this->_query_id : $query_id; } public function num_rows($query_id = '') { $query_id = (!$query_id) ? $this->_query_id : $query_id; } public function result($result = '', $row = 0, $cols = 0) { $result = !$result ? $this->_query_id : $result; } public function num_fields($result = '') { $result = !$result ? $this->_query_id : $result; } public function affected_rows() { } public function field_name($result = '', $i = 0) { $result = !$result ? $this->_query_id : $result; } public function field_type($result = '', $i = 0) { $result = !$result ? $this->_query_id : $result; } function start_transaction() { } function commit() { } function rollback() { } } ?>