问题
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