connection odbc php

1

Thanks for your help colleagues, I'm just beginning in the world of programming, I appreciate your help. I'm doing a search menu with php with odbc connection. The connection file is as follows:

<? 
$dsn = "PG_EXCEL"; 
$usuario="postgres";
$clave="telguasa+1";

$cid=odbc_connect($dsn, $usuario, $clave);

if (!$cid){
    exit("<strong>Ya ocurrido un error tratando de conectarse con el origen de datos.</strong>");
}

The search menu is the following but it turns out that I can not visualize the files according to the date that is consulted the code is the following:

<?php
include('conexion.php');

$desde = $_POST['desde'];
$hasta = $_POST['hasta'];

//COMPROBAMOS QUE LAS FECHAS EXISTAN
if(isset($desde)==false){
    $desde = $hasta;
}

if(isset($hasta)==false){
    $hasta = $desde;
}

//EJECUTAMOS LA CONSULTA DE BUSQUEDA

$registro = "SELECT * FROM tarificado.rep_con WHERE fecha_dcms BETWEEN '$desde' AND '$hasta'";


//CREAMOS NUESTRA VISTA Y LA DEVOLVEMOS AL AJAX

echo '<table class="table table-striped table-condensed table-hover">
            <tr>
                <th width="200">central</th>
                <th width="150">centrales_nombre</th>
                <th width="150">fecha_dcms</th>
                <th width="150">archivo_dcms</th>
                <th width="150">correlativo_dcms</th>
                <th width="150">bytes_dcms</th>
                <th width="150">archivo_ivr</th>
                <th width="150">correlativo_ivr</th>
                <th width="150">fecha_ivr</th>
                <th width="150">bytes_ivr</th>
                <th width="150">ivr_num_eventos</th>
                <th width="150">dif_bytes</th>      
            </tr>';
if(($registro)>0)
{
    while($registro2 = odbc_fetch_array($registro)){ 
        echo '<tr>
                <td>'.$registro2['Central'].'</td>
                <td>'.$registro2['centrales_nombre'].'</td>
                <td>'.$registro2['fecha_dcms'].'</td>
                <td>'.$registro2['archivo_dcms'].'</td>
                <td>'.$registro2['correlativo_dcms'].'</td>
                <td>'.$registro2['bytes_dcms'].'</td>
                <td>'.$registro2['archivo_ivr'].'</td>
                <td>'.$registro2['correlativo_ivr'].'</td>
                <td>'.$registro2['fecha_ivr'].'</td>
                <td>'.$registro2['bytes_ivr'].'</td>
                <td>'.$registro2['ivr_num_eventos'].'</td>
                <td>'.$registro2['dif_bytes'].'</td>
                </tr>';
    }
}else{
    echo '<tr>
                <td colspan="6">No se encontraron resultados</td>
            </tr>';
}
echo '</table>';
?>

What will I be doing wrong? I appreciate your comments very much.

Greetings.

    
asked by Grindor 18.04.2018 в 23:56
source

1 answer

0

Your problem is here:

if(($registro)>0)

The variable $ register is a string, and a string evaluated as integer returns 0 in PHP. I think you need an instruction to run the query that you have saved in that variable.

Something like:

$registro = odbc_exec($cid, $registro);
    
answered by 19.04.2018 / 00:38
source