search
Homephp教程php手册MySQL中如何存取二进制文件

MySQL中如何存取二进制文件

Jun 13, 2016 am 11:21 AM
mysqltestbinarycodecreatehowaccessdocumenttestusesurfaceillustratefirst

如何存取二进制文件,用以下代码说明

首先创建测试表testtable
CREATE TABLE testtable ( id INT(5) NOT NULL AUTO_INCREMENT PRIMARY KEY,filename CHAR(255),data LONGBLOB );

将文件存入表中
mysql_connect( "localhost", "root", "password"); //连接数据库
mysql_select_db( "database"); //选定数据库
$filename="" //这里填入二进制文件名
$data = addslashes(fread(fopen($filename, "r"), filesize($filename)));//打开文件并规范化数据存入变量$data中

$result=mysql_query( "INSERT INTO testtable (filename,data) VALUES ('$filename','$data')");//数据插入到数据库test表中

mysql_close();
?>

从表中取回文件


if($id) {

mysql_connect( "localhost", "root", "password");

mysql_select_db( "database");
$filename="" //这里填入二进制文件名

$query = "select data from testtable where filename=$filename";
$result = mysql_query($query);

$data = mysql_result($result,0, "data");

?>

这里要注重的是,PHP一般只支持小于2M的文件,假如要存取大于2M的文件,那就要进系统方面的设置了。


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment

SecLists

SecLists

SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor