2

I want to convert longblob data to varchar or text.
Data saved in database like "[BLOB - 2 B]".
I want to convert this data.

How to fix it?

Ruchi Patel
  • 122
  • 1
  • 8
  • Follow the link: [https://stackoverflow.com/questions/8627621/how-do-i-convert-blob-into-varchar-in-mysql](https://stackoverflow.com/questions/8627621/how-do-i-convert-blob-into-varchar-in-mysql). – Mahbubul Islam Jul 21 '17 at 06:02
  • Not working any solutions.Can you please give me an another solutions or links? – Ruchi Patel Jul 21 '17 at 06:16
  • Follow this link : https://stackoverflow.com/questions/948174/how-do-i-convert-from-blob-to-text-in-mysql – Hemdip Jul 21 '17 at 06:20
  • Is that for codeigniter sessions database? –  Jul 21 '17 at 07:34
  • If you are still having trouble, please provide `SELECT HEX(LEFT(blob_col, 10))` and some clue of what the characters should be. – Rick James Sep 02 '17 at 21:15

4 Answers4

2

In mysql you can run:

select cast(column as char) from tablename

Or in php you can use mysql_fetch_object function to get object

Liu.handy
  • 59
  • 3
0

Data saved in BLOB datatype in MySQL, can not be used to read the value directly. Instead, you can type-cast the datatype into some specified character set and then read value from it.

For example:-

In DOCUMENT table, DESCRIPTION field is of BLOB datatype. Then to read the data in MySQL you can cast it like e-g

SELECT CAST(DESCRIPTION AS CHAR(10000) CHARACTER SET utf8) FROM DOCUMENT;

CAST(DESCRIPTION AS CHAR(10000) CHARACTER SET utf8 will convert the BLOB datatype into character set which can be read.

dhruv jadia
  • 1,684
  • 2
  • 15
  • 28
Muneeb Shahid
  • 223
  • 4
  • 13
0

You can use the CONVERT function :

SELECT CONVERT(column USING utf8) FROM table;

as explained in another post here

komarios
  • 147
  • 4
-1

If your blob file is just a text file then, just normal query should do the job.

$query = $this->db->select('column_name_that_blob_data')->from('table_name')->get();
var_dump($query->result());
Rabin Lama Dong
  • 2,422
  • 1
  • 27
  • 33