Select a portion from a MySQL Blob Field

前端 未结 2 979
Happy的楠姐
Happy的楠姐 2020-12-28 19:12

I have a table containing lots of data and one of them is a blob. I some times needs to look into this blob for data using PHP.

I do:

select `desc` f         


        
2条回答
  •  夕颜
    夕颜 (楼主)
    2020-12-28 19:58

    This query:

    SELECT 
      CONCAT(
        '...', 
        SUBSTR(`description`, 
          LOCATE('Nam rhoncus', `description`) - 10, 
          (LENGTH('Nam rhoncus') + 20)), 
        '...') AS `description`
    FROM table 
    WHERE `description` LIKE '%Nam rhoncus%';
    

    (I broke it down like this so it's easier to read)

    this will output:

    ...m auctor. Nam rhoncus, purus eg...

    So in your PHP you can do:

    NOTE: Ill be careful using mysql reversed words, this is why I use description instead.

提交回复
热议问题