Error printing a text type record in php using pdo and informix

0

Friends please, I need help, Until yesterday, I did not have a problem printing records that I have in my informix database from php using pdo. But yesterday I came across a type registry (text), and it printed me (resource id #) As I said any other type of text I have no problem. Next I will put them as I call a table with the following structure: PROOF

codigo              int
clave               char(12)
registro            varchar(10)
contenido           text

Php code

 $ls_query = ("select * from PRUEBA");
    $ls_res_usr = $ls_conn->query($ls_query);                           
    $ls_result = $ls_res_usr->fetchAll();
    foreach($ls_result AS $ls_res_usr)
    {
        $id_cod= trim($ls_res_usr[0]);
        $id_cla= trim($ls_res_usr[1]);
        $id_reg= trim($ls_res_usr[2]);
        $id_con= trim($ls_res_usr[3]);
    echo $id_cod . "-".$id_cla . "-".$id_reg . "-".$id_con;
    }
    unset ($ls_res_usr);

And the result I get is this:

1-1AB-La Paz-(Resource id #2)
4-3FG-La Paz-(Resource id #3)
5-1AB-Santa Cruz-(Resource id #4)
18-5TY-Oruro-(Resource id #5)
24-3wE-Sucre-(Resource id #6)

...

And really, you should show me a text Please your help.

    
asked by dante valencia92 08.12.2016 в 15:18
source

2 answers

0

I managed to show only one record, now the theme is to apply the foreach.

$sentencia = $cona->prepare("select * from PRUEBA where clave = '1AB' ");
$sentencia->execute();
$sentencia->bindColumn(1, $tipo, PDO::FETCH_ASSOC);
//$sentencia->bindColumn(2, $lob, PDO::PARAM_LOB);
$sentencia->fetch(PDO::FETCH_BOUND);
echo ($tipo);

And if I get the text I want.

    
answered by 08.12.2016 в 22:34
0

According to the documentation:

  

PDO :: query : A good feature of PDO::query() is that it allows you to iterate over the whole of rows returned by a successful SELECT statement execution.

     

Although this function is documented only by having a single parameter, additional arguments can be passed to this function. These will be treated as if you were calling PDOStatement::setFetchMode() with the object of the resulting statement.

Try to do so:

$ls_query = "select * from PRUEBA";
foreach($cona->query($ls_query, PDO::FETCH_ASSOC) AS $ls_res_usr) {

    $id_cod= trim($ls_res_usr['codigo']);
    $id_cla= trim($ls_res_usr['clave']);
    $id_reg= trim($ls_res_usr['registro']);
    $id_con= trim($ls_res_usr['contenido']);
    echo $id_cod . "-".$id_cla . "-".$id_reg . "-".$id_con;
}
unset ($ls_res_usr);

// UPDATE

For a query that needs to be executed multiple times, a better performance will be obtained if a PDOStatement object is prepared using PDO :: prepare ()

$stmt = $cona->prepare("select * from PRUEBA");
$stmt->execute();
$rows = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach($rows as $row) {

    $id_cod= trim($row['codigo']);
    $id_cla= trim($row['clave']);
    $id_reg= trim($row['registro']);
    $id_con= trim($row['contenido']);
    echo $id_cod . "-".$id_cla . "-".$id_reg . "-".$id_con;
}
    
answered by 08.12.2016 в 17:06