Postgre连接类
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Postgre连接类相关的知识,希望对你有一定的参考价值。
<?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() { } } ?>
以上是关于Postgre连接类的主要内容,如果未能解决你的问题,请参考以下文章
使用 AWS 驱动程序与 Redshift 的 R 连接不起作用,但可以与 Postgre 驱动程序一起使用