How to read resource (2) of type (stream) with PDO_INFORMIX?

0

I have a problem with the return of the information I perform with PDO_INFORMIX , then I show you my case:

1. Database:

INFORMIX

2. Schema:

-Table: cartas

-Campos:

|id      | codigo | titulo     |contenido   |
---------------------------------------------
| SERIAL | INTEGER|VARCHAR(15) | TEXT       |

3. Contents of the table:

-id: 1 -code: 25463985 -title: Requisitos Especiales

-content:

<div><strong>DOCUMENTOS PARA EL AÑO 2018</strong></div>
<div>&nbsp;</div>
<ul>
<li><u>DOCUMENTOS NECESARIOS PARA REALIZAR EL TRAMITE:</u></li></ul>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *Detrffghfjh Fasdasdasd as Iasdasdasdasd asdde.</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *Detrffghfjh Fasdasdasd as Iasdasdasdasd asdde.</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *Detrffghfjh Fasdasdasd as Iasdasdasdasd asdde.</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *Detrffghfjh Fasdasdasd as Iasdasdasdasd asddeDetrffghfjh Fasdasdasd as Iasdasdasdasd asdde.</div>
<div>&nbsp;</div>
<ul>
<li><u>DOCUMENTOS PARA ASDASDASDASD:</u></li></ul>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *Detrffghfjh Fasdasdasd as Iasdasdasdasd asdde.</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *Detrffghfjh Fasdasdasd as Iasdasdasdasd asddeDetrffghfjh Fasdasdasd as Iasdasdasdasd asdde.</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *Detrffghfjh Fasdasdasd as Iasdasdasdasd asddeDetrffghfjh Fasdasdasd as Iasdasdasdasd asdde.</div><div>&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *Detrffghfjh Fasdasdasd as Iasdasdasdasd asdde<br></div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *Detrffghfjh Fasdasdasd as Iasdasdasdasd asddeDetrffghfjh Fasdasdasd as Iasdasdasdasd asdde</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *Detrffghfjh Fasdasdasd as Iasdasdasdasd asddeDetrffghfjh Fasdasdasd as Iasdasdasdasd asddeDetrffghfjh Fasdasdasd as Iasdasdasdasd asdde</div>
<div>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; *Detrffghfjh Fasdasdasd as Iasdasdasdasd asdde.</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div>&nbsp;</div>
<div><strong>MAYORES INFORMES</strong></div>
<div>Carrera Detrffghfjh Fasdasdasd as Iasdasdasdasd asdde </div>
<div>Detrffghfjh Fasdasdasd as Iasdasdasdasd asdde</div>

I am making the connection to the Database by means of PDO_INFORMIX in the following way:

CONNECTION:

$conexion = new PDO("informix:host=127.0.0.1;service=sqldesarrol;database=bdtest; server=online_shm;protocol=onsoctcp;EnableScrollableCursors=1;", "userTest", "PassTest");
$conexion->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

INQUIRY:

$sql    = "SELECT * FROM cartas";
$prep   = $conexion->prepare($sql);   
$prep->execute();                   
$result = $prep->fetchAll(PDO::FETCH_ASSOC);
var_dump($result);

I realize a var_dump to see the information returned and I have the following result.

RESULT:

array(1) {
  [0]=>
  array(5) {
    ["ID"]=>
    string(1) "1"
    ["CODIGO"]=>
    string(8) "25463985"
    ["TITULO"]=>
    string(21) "Requisitos Especiales"
    ["CONTENIDO"]=>
    resource(2) of type (stream)

  }
}

I do not understand why I return the content of the content field that way.

WHAT HAS BEEN TESTED:

if(is_resource($result[0]['CONTENIDO']))
{
    echo get_resource_type($result[0]['CONTENIDO']);
}

Returns: stream

Based on that test I used the function get_resources but I get the following error:

<b>Warning</b>: get_resources() expects parameter 1 to be string, resource given in <b>C:\....

What I'm most curious about is that if I do the following:

echo $result[0]['EDUFORCONTEX'];

It gives me as a result: Resource id #2

    
asked by Andrés 27.12.2017 в 23:32
source

1 answer

1

Try to do it like this:

$conexion = new PDO("informix:host=127.0.0.1;service=sqldesarrol;database=bdtest; server=online_shm;protocol=onsoctcp;EnableScrollableCursors=1;", "userTest", "PassTest");
$conexion->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$sql    = "SELECT id, codigo, titulo, contenido FROM cartas";
$prep   = $conexion->prepare($sql);
$prep->execute();

/* AQUI bindeamos las columnas a variables y su tipo */
$prep->bindColumn(1, $id, PDO::PARAM_INT);
$prep->bindColumn(2, $codigo, PDO::PARAM_STR);
$prep->bindColumn(3, $titulo, PDO::PARAM_STR);
$prep->bindColumn(4, $resource, PDO::PARAM_LOB);

/*ALMACENAMOS EL RESULTADO*/
$result = [];
while ($prep->fetch(PDO::FETCH_BOUND)) {

    $result[] = [
        'id'=> $id,
        'codigo'=> $codigo,
        'titulo'=> $titulo,
        'contenido'=> stream_get_contents($resource),
    ];
}
    
answered by 28.12.2017 / 13:03
source