Foros del Web » Programando para Internet » PHP »

Problema con PostgreSql y PHP

Estas en el tema de Problema con PostgreSql y PHP en el foro de PHP en Foros del Web. Saludos a todos/as! Les empiezo a escribir por un problema que tengo en un sistema que estoy desarrollando. Les paso a comentar: Primeramente tengo una ...
  #1 (permalink)  
Antiguo 10/02/2010, 13:42
 
Fecha de Ingreso: julio-2009
Ubicación: Córdoba capital
Mensajes: 8
Antigüedad: 14 años, 8 meses
Puntos: 0
Exclamación

Saludos a todos/as!

Les empiezo a escribir por un problema que tengo en un sistema que estoy desarrollando.

Les paso a comentar:

Primeramente tengo una tabla llamada t_config_filas, que devuelve un string de los campos a sumar para armar otra consulta que se ejecutará posteriormente
(Ej: "ing_dir_reg_t + ing_est_reg_t + ing_priv_reg_t")

Lo interesante del problema es que en primera instancia, funciona perfectamente, incluso se ejecuta 4 veces.

Posteriormente surge el problema...

Pongo una depuración que he hecho:

Código:
CAMPO: matricula_v
VALOR_CAMPO: 10
CONSULTA_FILAS: select suma from rmatri_ini10.t_config_filas where tipo_carga = 'I' and tipo_edu = 1 and nivel = 1 and total = 'matricula_v'
DATOS:Array ( [suma] => ing_dir_reg_v + ing_est_reg_v + ing_priv_reg_v )
SUMA FILA:select (ing_dir_reg_v + ing_est_reg_v + ing_priv_reg_v) as suma from rmatri_ini10.t_inicial_totales where cue = 1402020 and anexo = 0 and tipoedu = 1 and nivel = 1
TOTAL:30
DATOS_SUMA:Array ( [suma] => 30 )

CAMPO: matricula_t
VALOR_CAMPO: 0
CONSULTA_FILAS: select suma from rmatri_ini10.t_config_filas where tipo_carga = 'I' and tipo_edu = 1 and nivel = 2 and total = 'matricula_t'
DATOS:Array ( [suma] => ing_dir_reg_t + ing_est_reg_t + ing_priv_reg_t )
SUMA FILA:select (ing_dir_reg_t + ing_est_reg_t + ing_priv_reg_t) as suma from rmatri_ini10.t_inicial where cue = 1402020 and anexo = 0 and tipoedu = 1 and nivel = 2 and anio = 1
TOTAL:0
DATOS_SUMA:Array ( [suma] => 0 )

CAMPO: matricula_t
VALOR_CAMPO: 0
CONSULTA_FILAS: select suma from rmatri_ini10.t_config_filas where tipo_carga = 'I' and tipo_edu = 1 and nivel = 2 and total = 'matricula_t'
DATOS:Array ( [suma] => 0 )
SUMA FILA:select (0) as suma from rmatri_ini10.t_inicial where cue = 1402020 and anexo = 0 and tipoedu = 1 and nivel = 2 and anio = 1
TOTAL:0
DATOS_SUMA:Array ( [suma] => 0 )

Como verán, en la ultima consulta, surge el problema. La CONSULTA_FILAS, al probarla directamente en la DB con el SQL Manager, devuelve bien los datos, pero al parecer aquí devuelve 0 al hacer el pg_fetch_array.

Según tengo entendido puede retornar 0 cuando hay algun tipo de problema, aunque se me escapa cual pueda ser. Ademas que funciona correctamente con los valores/consultas anteriores. Incluso utilizando los mismos valores/strings que deberia retornar en los campos de la DB.

Código PHP:
private function valorFila($campo,$valor_campo)
    {
        
$sql "select suma from rmatri_ini10.t_config_filas where tipo_carga = '".$this->tipo_carga."' and tipo_edu = ".$this->id_tipo_edu." and nivel = ".$this->id_nivel." and total = '".$campo."'";
        
$this->dbh->prepare($sql);
        if(
$this->dbh->execute())
            {
                if(
$this->tipo_carga == "I")
                    {
                        
$tabla "t_inicial";
                    }
                else    
                    {
                        
$tabla "t_trayectoria";
                    }
                    
                if(
$this->anio == 'total')
                    {
                        
$tabla .= '_totales';
                    }
                
                
$error 0;
                
                if(
$this->dbh->numRows() > 0)
                {
                    while(
$datos $this->dbh->fetch())    // aca surge el problema
                    
{
                    
                        
$sql_suma "select (".$datos['suma'].") as suma from rmatri_ini10.".$tabla." where cue = ".$this->cue." and anexo = ".$this->anexo." and tipoedu = ".$this->id_tipo_edu." and nivel = ".$this->id_nivel;
                        
                        if(
$this->anio != total)
                            {
                                
$sql_suma .= " and anio = ".$this->anio;
                            }
                            
                        
$this->dbh->prepare($sql_suma);
                        
$this->dbh->execute();
                        
                        
$datos_suma $this->dbh->fetch();
                        
                        echo 
"<p>CAMPO: ".$campo."<br />VALOR_CAMPO: ".$valor_campo."<br />CONSULTA_FILAS: ".$sql."<br />DATOS:";
                        
print_r($datos);
                        echo 
"<br />SUMA FILA:".$sql_suma."<br />TOTAL:".$datos_suma['suma']."<br />DATOS_SUMA:";
                        
print_r($datos_suma);
                        echo 
"</p>";
                        
                        if(
$valor_campo != $datos_suma['suma'])
                        {
                            
$error++;
                        }
                    }
                
                    return 
$error;
                }
            }
    } 
Finalmente se queda bucleando mostrando la ultima depuración una y otra vez hasta entregar un timeout.


Cualquier comentario u aporte es bienvenido para intentar solucionar el inconveniente.

Desde ya, muchisimas gracias por responder.

Saludos desde Córdoba.

Ofesad

Pd: Si no se entiende algo, haganmelo saber!
Necesito solucionar esto lo antes posible porque es para un sistema bastante importante.
Realmente me llama mucho la atención este tipo de error...

Gracias por leer.

Bueno... esto es raro...

Por probar, en vez de usar un while, puse un foreach... funcionó de mil maravillas =S

Extrañisimo, pero bueno, cumple con lo que necesito.

Problema solucionado... mas bien parchado, pero bueno, el resultado es igual de bueno :P

Gracias por leer.


Saludos desde Córdoba, Argentina.

Ofesad.

Última edición por GatorV; 10/02/2010 a las 15:35

Etiquetas: postgresql
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 10:24.