Foros del Web » Programación para mayores de 30 ;) » Bases de Datos General » PostgreSQL »

problema con parametrs del pg_connect

Estas en el tema de problema con parametrs del pg_connect en el foro de PostgreSQL en Foros del Web. hola a todos Tengo el siguiente problema sucede que cuando trato de hacer un pg_connect con php y le paso los parametros a la conextion ...
  #1 (permalink)  
Antiguo 16/11/2009, 19:53
 
Fecha de Ingreso: septiembre-2008
Mensajes: 23
Antigüedad: 15 años, 7 meses
Puntos: 0
problema con parametrs del pg_connect

hola a todos

Tengo el siguiente problema sucede que cuando trato de hacer un pg_connect con php y le paso los parametros a la conextion como el usuario ,la clave y la base de datos el por alguna razon no me conecta pero lo curioso es que cuando reviso el log de postgresql el me dice:

2009-11-16 20:27:22 COT FATAL: la autentificaci?n Ident fall? para el usuario <<postgres>>
2009-11-16 20:27:23 COT LOG: el nombre de usuario entregado (www-data) y el nombre de usuario autentificado (postgres) no coinciden

y pues revisandolo parece ser qu ese le esta enviando como parametor el nombre de usuario del apache la cosa es que no se por que pueda pasar

Gracias por su tiempo y atencion.
  #2 (permalink)  
Antiguo 25/11/2009, 09:29
Avatar de webness  
Fecha de Ingreso: enero-2009
Ubicación: BOGOTA
Mensajes: 312
Antigüedad: 15 años, 3 meses
Puntos: 5
Respuesta: problema con parametrs del pg_connect

en mi caso particular me suele pasar, al momento de especificar el host, le doy la IP del servidor la de acceso internet o de red y no me conecta, y al cambiarlo por localhost si conecta. Supongo que esto se da en mi caso, tanto porque el codigo como la Db estan en el mismo servidor.


te adjunto una clase que hice con la que me conecto a postgresql y a mysql, usando los mismos metodos

Código PHP:
<?php

/**
 * Clase que contiene metodos publicos unicos para la conexion a bases de datos mysql y/o postgresql
 * @author Gustavo Adolfo Alzate
 * @copyright webness
 * @version 1.0
 */
class DBMS 
{
    
/**
     * tipo de base de datos a usar 1:MYSQL, 2:POSTGRESQL
     * @var int
     */
    
private $intDataBase;
    
    
/**
     * ip o url del servidor de base datos
     * @var string
     */
    
private $strServer;
    
    
/**
     * usuario de conexion al servidor de base de datos
     *
     * @var string
     */
    
private $strUser;
    
    
/**
     * password para la conexion a la base de datos
     *
     * @var string
     */
    
private $strPassword;
    
    
/**
     * nombre de la base de datos con la que se establece conexion
     *
     * @var string
     */
    
private $strDataBase;
    
    
/**
     * identificador de conexion
     *
     * @var conection<string>
     */
    
private $con;
    
    
/**
     * resultado de una consulta sql
     *
     * @var result<string>
     */
    
private $result;
    
    
/**
     * cadena sql con la sintaxis de paginacion
     *
     * @var string
     */
    
private $strPaging;
    
    
/**
     * constructor
     *
     * @param int $intDataBase
     * @param string $strServer
     * @param string $strUser
     * @param string $strPassword
     * @param string $strDataBase
     * @return DBMS
     */
    
public function DBMS($file)
    {
        
$db_config parse_ini_file($file);
        
        
$this->intDataBase     $db_config["type"];
        
$this->strServer    $db_config["server"];
        
$this->strUser         $db_config["user"];
        
$this->strPassword     $db_config["password"];
        
$this->strDataBase     $db_config["data_base_name"];
    }
    
    public function 
getTempTable($strTable)
    {
        switch(
$this->intDataBase)
        {
            case 
1$this->getTempTableMysql($strTable);  break;
            case 
2$this->getTempTablePostgresql($strTable); break;
        }    
    }
    
    private function 
getTempTablePostgresql($strTable)
    {
        
$this->connect();
        
$this->result pg_query("SELECT * FROM ".$strTable);
    }
    
    private function 
getTempTableMysql($strTable)
    {
        
    }
    
    
    
/**
     * establece conexion con la base de datos
     */
    
public function connect()
    {
        if (!isset(
$this->con))
        {
            switch (
$this->intDataBase)
            {
                case 
1$this->connectMysql();break;
                case 
2$this->connectPostgresql();break;
            }
        }
    }
    
    
/**
     * finaliza conexion con la base de datos
     */
    
public function shutdown()
    {
        if (!isset(
$this->con))
        {
            switch (
$this->intDataBase)
            {
                case 
1$this->shutdownMysql();break;
                case 
2$this->shutdownPostgresql();break;
            }
        }
    }
    
    private function 
shutdownMysql()
    {
        
mysql_free_result($this->result);
    }
    
    private function 
shutdownPostgresql()
    {
        
pg_freeresult($this->result);
    }
    
    
/**
     * ejecuta una consulta a la base de datos
     *
     * @param string $strSql
     */
    
public function execute($strSql)
    {
        switch (
$this->intDataBase)
        {
            case 
1$this->result $this->executeMysql($strSql);break;
            case 
2$this->result $this->executePostgresql($strSql);break;
        }    
        
        return 
$this->result;
    }
    
    
/**
     * retorna el numero de filas afectadas por una consulta SQL
     *
     * @return unknown
     */
    
public function getNumRows()
    {
        
$intNumRows 0;
        
        switch (
$this->intDataBase)
        {
            case 
1$intNumRows $this->getNumRowsMysql();break;
            case 
2$intNumRows $this->getNumRowsPostgresql();break;
        }
        
        return 
$intNumRows;
    }
    
    
/**
     * Retorna un recurso especifico de una base de datos como resultado de una consulta SQL
     * @deprecated se removera este metodo para entregarle solo a las otras clases las filas evitando problemas de compatibilidad
     *             con bases de datos
     * @return result
     */
    
public function getResult()
    {
        return 
$this->result;    
    }
    
    
/**
     * obtiene el string sql correspondiente para una paginacion
     *
     * @param int $intStart
     * @param int $intLimit
     * @return string
     */
    
public function getStrPaging($intStart,$intLimit)
    {
        switch(
$this->intDataBase)
        {
            case 
1$this->strPaging $this->getStrPagingMysql($intStart,$intLimit);break;
            case 
2$this->strPaging $this->getStrPagingPostgresql($intStart,$intLimit);break;
        }

        return 
$this->strPaging;
    }
    
    private function 
getStrPagingMysql($intStart,$intLimit)
    {
        if(
$intStart == && $intLimit == 0)
        {
            
$this->strPaging "";
        }
        else
        {
            
$this->strPaging "LIMIT ".$intStart.",".$intLimit;
        }
        
        return 
$this->strPaging;    
    }
                     
    private function 
getStrPagingPostgresql($intStart,$intLimit)
    {
        if(
$intStart == && $intLimit == 0)
        {
            
$this->strPaging "";
        }
        else
        {
            
$this->strPaging "OFFSET ".$intStart." LIMIT ".$intLimit;
        }
        
        return 
$this->strPaging;
    }
    
    
/**
     * retorna una fila especifica del resultado de una columna
     *
     * @param  int $intRow
     * @return row
     */
    
public function getRowAt($intRow,$strTypeRow)
    {
        
$row="";
        
        switch (
$this->intDataBase)
        {
            case 
1$row $this->getRowAtMysql($intRow,$strTypeRow);break;
            case 
2$row $this->getRowAtPostgresql($intRow,$strTypeRow);break;
        }

        return 
$row;
    }
    
    public function 
createTempTable($strSQL)
    {
        switch (
$this->intDataBase)
        {
            case 
1$row $this->createTempTableMysql();break;
            case 
2$row $this->createTempTablePostgresql($strSQL);break; //TODO
        
}
    }
    
    private function 
createTempTablePostgresql($strSQL)
    {
        
pg_query($strSQL);
    }
    
    private function 
connectMysql()
    {
        
$this->con mysql_query($this->strServer,$this->strUser,$this->strPassword);
        
mysql_select_db($this->strDataBase,$this->con);
    }
    
    private function 
connectPostgresql()
    {
        
$strConn "host=".$this->strServer." port=5432 password = ".$this->strPassword." user = ".$this->strUser.
                    dbname = "
.$this->strDataBase;
        
        
$this->con pg_connect($strConn);
    }
    
    private function 
executeMysql($strSql)
    {
        
$this->result mysql_query($strSql,$this->con);
        
        return 
$this->result;
    }
    
    private function 
executePostgresql($strSql)
    {
        
$this->result = @pg_query($this->con,$strSql);
        return 
$this->result;
    }
    
    private function 
getNumRowsMysql()
    {
        return 
mysql_num_rows($this->result);
    }
    
    private function 
getNumRowsPostgresql()
    {
        return 
pg_num_rows($this->result);
    }
    
    
/** @todo HACER CAMBIO PARA QUE EL ARREGLO RETORNADO SEA UN ARREGLO ESCALAR */
    
private function getRowAtMysql($intRow,$strTypeRow)
    {
        @
mysql_data_seek($this->result,$intRow);
        return @
mysql_fetch_array($this->result);
    }
    
    
/**
     * Guarda en un arreglo bien sea escalar o asociativo todos los elementos de una fila seleccionada de una consulta exitosa
     *
     * @param array $row fila de una consulta
     * @param string $strTypeRow tipo de elementos que desea obtener e=escalar a=asociativo
     * @return array
     */
    
private function pushRowToArray($row,$strTypeRow)
    {
    
$scalarRow = array();
        foreach (
$row as $key=>$value)
        {
            if (
$strTypeRow == "e")
            {
                if(
is_int($key))
                {
                        
$scalarRow[$key] = $value;
                }
            }
            else
            {
                if(!
is_int($key))
                {
                        
$scalarRow[$key] = $value;
                }
            }
        }

        return 
$scalarRow;
    } 
    
    private function 
getRowAtPostgresql($intRow,$strTypeRow)
    {
        
$row pg_fetch_array($this->result,$intRow);
        return 
$this->pushRowToArray($row,$strTypeRow);
    }
}

?>
la configuracion de los parametros se hace en un INI cuya estructrura es esta

Código INI:
Ver original
  1. [data_base]
  2. data_base_name = db_name
  3. server = localhost
  4. user = your_user
  5. password = your_password
  6. type = 2

siendo type=2 mysql y type=1 mysql
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 15:32.