How to read text from the BLOB format?

好久不见. 提交于 2019-12-14 02:32:45

问题


I am saving pdf/word documents in DB by saving them in blob format. Now I want to read it as string. My intention is just to read saved blob content as string, so that I can search for text.

For example: If few different types of documents are uploaded and I want to search for a text into it.

Ho it can be achieved ?

Thanks in advance.


回答1:


First of all, BLOB is a BINARY LOB and You used it correctly - to store tha files into a database. As it is BINARY also the data in this column is stored in its binary form. Therefore I'm not sure if You can search for a text within the binary data...

Anyway, You should be able to do this by:

$conn = oci_connect('user', 'pass', 'server');
$q = "SELECT blob_column FROM my_blob_table WHERE my_blob_id = :id";
$stmt = oci_parse($conn, $q);
oci_bind_by_name($stmt, ':id', $id);
oci_execute($stmt);
$res = oci_fetch_assoc($stmt);
$blob = $res['blob_column']->read($res['blob_column']->size());
var_dump($blob);

If You want to store the data as a text, use CLOB (CHARACTER LOB) column instead.



来源:https://stackoverflow.com/questions/10683885/how-to-read-text-from-the-blob-format

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!