PHP operation MySQL Intermediate blob farm

Source: Internet
Author: User

1. mysql in the Blob field type

The type of BLOB farm is used to store binary data.
MySQL in. Blob It is a series of types. Contains: Tinyblob, Blob, Mediumblob, Longblob. vary in size.
MySQL four types of blobs

Tinyblob: Maximum 255 bytes
Blob: 65K Max
Mediumblob: 16M Max
Longblob: 4G Max

Note: Assume that the file you are storing is too large. The performance of the database can be degraded very much.

2. PHP Operation Blob case

[1] Operating news content

<?

Phpmysql_connect ("localhost", "root", "password"); Connect database mysql_select_db ("databases"); Selected database//data insertion: $CONTENT = "test content"; $CONTENT for news content $compress_content = Bin2Hex (gzcompress ($CONTENT)); $result =mysql_query ("INSERT INTO News" Value (' $COMPRESS _content ') ");//data is inserted into the database news table//show: $query =" Select data from testtable where Filename= $filename "; $result = mysql_query ($query); [Email protected] ($result ["compress_content"]; echo $COMPRESS _content;? >

[2] Storing pictures

<?

PHP mysql_connect ("localhost", "root", "password");//Connect to the database mysql_select_db ("database");///////// storage: $ Filename= ""//fill in the picture path $COMPRESS _content = Addslashes (Fread (fopen ($filename, "R"), FileSize ($filename)));// Open the file and normalize the data into the variable $data $result=mysql_query ("INSERT INTO News (' $COMPRESS _content ')");//data is inserted into the Database test table/ /show: Ob_end_clean (); Header ("Content-type:image/gif"); $query = "Select data from testtable where Filename= $filename"; $result = mysql_query ($query); Echo $result ["compress_content"];? >


Copyright notice: This article blog original articles, blogs, without consent, may not be reproduced.

PHP operation MySQL Intermediate blob farm

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.