doutu6658
2019-08-02 15:05 阅读 92

如何在数据库中保存图像?

I want to save images in a mysql database. I read one option:

INSERT INTO tblname(ID,IMAGE) VALUES(1,LOAD_FILE('C:/path.jpg'));

This option save a null value in the field, when realise select rows of the table, the result is a null value and also don't work in a sql php query.

Any idea?

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • doudengjin8251 doudengjin8251 2019-08-02 15:53

    you can save as LONGBLOB datatype in mysql, to store it binary in the database.

    CREATE TABLE pictures (
        'id' INTEGER UNSIGNED NOT NULL AUTO_INCREMENT,
        'image' LONGBLOB NOT NULL,
      PRIMARY KEY ('id')
    )
    

    then

    $sql = "INSERT INTO pictures(image)               
            VALUES('".file_get_contents($tmp_image)."')";
    
    点赞 评论 复制链接分享

相关推荐