如何阅读从BLOB格式的文本? [英] How to read text from the BLOB format?

查看:362
本文介绍了如何阅读从BLOB格式的文本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我其储存在BLOB格式保存PDF / Word文档中的DB。
现在,我想读它作为字符串。
我的目的只是为了读取保存BLOB内容为字符串,这样我就可以搜索文本。

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.

何可以实现吗?

先谢谢了。

推荐答案

首先,BLOB是一个二进制LOB和你正确使用它 - 对Tha文件存储到数据库中。因为它是二元也在此列中的数据被存储在它的二进制形式。因此,我不知道,如果你可以搜索二进制数据...

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);

如果您希望将数据存储为文本,使用CLOB(CHARACTER LOB)列代替。

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

这篇关于如何阅读从BLOB格式的文本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆