Shimon
Shimon

Reputation: 13

Retrieving a database column that contains xml

I must admit it is late and I am tired. Perhaps too tired to see what is in front of me! I have a MS database table where 1 column contains xml data. I need to retrieve the data into a variable (or whatever) and then display it.

I am connected to the database. I can retrieve data from any other column. However, when I execute this statement on column 1(which contains the xml):

$Text = sqlsrv_get_field( $results, 1); 

I get this error: SearchPatentID(): 22872056 is not a valid stream resource...

I do NOT get this error on any other column in the table. So,

$Whatever = sqlsrv_get_field( $results, 3); 

works just fine. I am not concerned about how to display the data, just how to get it so I can do what I need.

thanks in advance it is ALWAYS greatly appreciated. Shimon

Upvotes: 0

Views: 115

Answers (1)

Shimon
Shimon

Reputation: 13

I finally found the answer to my problem.

$stream = sqlsrv_get_field( $results, 1, SQLSRV_PHPTYPE_STREAM( SQLSRV_ENC_CHAR));

Then you can loop through $stream to display or do whatever you want with the data.

while( !feof( $stream))
{ 
    $str = fread( $stream, 10000);
    echo $str;
}

Upvotes: 1

Related Questions