dongou1970
2017-06-06 03:40
浏览 48
已采纳

mysql BLOB在php中操作

In mysql, I have a db column with BLOB data type.

The blob data looks something like this:

{\"Name\":\"Mike Smith\",\"Number\":\"1\"}

or

[{\"Name\":\"Mike Smith\"},{\"Name\":\"Jon Doe\",\"Spaces\":\"1\"},{\"Name\":\"My Space(s)\"},{\"Name\":\"Rear\"}]

I am trying to detect the content in php and saving the string as a variable as such:

{\"Name\":\"Mike Smith\",\"Number\":\"1\"} 
BECOMES -> Mike Smith(1)

And...

[{\"Name\":\"Mike Smith\"},{\"Name\":\"Jon Doe\",\"Number\":\"1\"},{\"Name\":\"My Space(s)\"},{\"Name\":\"Rear\"}]   
BECOMES --> Mike Smith, Jon Doe(1), My Space(s), Rear

I am not familiar with BLOB data type and wanted to get some help from the community. How would I manipulate the BLOB data to above?

Any suggestions will be much appreciated.

图片转代码服务由CSDN问答提供 功能建议

在mysql中,我有一个带 BLOB 数据类型的db列。

blob数据如下所示:

  {\“Name \”:\“Mike Smith \”,\“Number \”:\  “1 \”} 
   
 
 

  [{\“Name \”:\“Mike Smith \  “},{\”Name \“:\”Jon Doe \“,\”Spaces \“:\”1 \“},{\”Name \“:\”My Space(s)\“},{\  “Name \”:\“Rear \”}] 
   
 
 

我正在尝试检测php中的内容并将字符串保存为变量:

  {\“Name \”:\“Mike Smith \”,\“Number \”:\“1 \”} 
BECOMES  - >  Mike Smith(1)
   
 
 

并且......

  [{\“Name \”:\“  Mike Smith \“},{\”Name \“:\”Jon Doe \“,\”Number \“:\”1 \“},{\”Name \“:\”My Space(s)\“}  ,{\“Name \”:\“Rear \”}] 
BECOMES  - >  Mike Smith,Jon Doe(1),My Space(s),Rear 
   
 
 

我不熟悉BLOB数据类型,希望从社区获得一些帮助 。 我如何操作上面的BLOB数据?

任何建议都将不胜感激。

  • 写回答
  • 好问题 提建议
  • 关注问题
  • 收藏
  • 邀请回答

1条回答 默认 最新

  • douzaipou3327 2017-06-06 04:55
    已采纳
    <?php
    
    $data = '[{\"Name\":\"Mike Smith\"},{\"Name\":\"Jon Doe\",\"Number\":\"1\"},
    {\"Name\":\"My Space(s)\"},{\"Name\":\"Rear\"}]';
    
    $data =  json_decode(stripslashes($data))  ;
    
     $string = '';
     for ($i=0; $i <sizeof($data) ; $i++) { 
    
     $d = $data[$i];
    
     if(isset($d->Number)){
        $number = '('.$d->Number.')';
     }
     else{
        $number = '';
     }
    
     $string .= ($d->Name).$number.',  ';
    
    }
    
    
    echo $string;
    
    评论
    解决 无用
    打赏 举报

相关推荐 更多相似问题