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

查看:37
本文介绍了如何从 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 是一个 BINARY LOB,您正确使用它 - 将 tha 文件存储到数据库中.由于它是 BINARY,因此该列中的数据也以二进制形式存储.因此,我不确定您是否可以在二进制数据中搜索文本...

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天全站免登陆