mysql 二进制数据_MySQL中的二进制数据

对于这样的表:

CREATE TABLE binary_data (

id INT(4) NOT NULL AUTO_INCREMENT PRIMARY KEY,

description CHAR(50),

bin_data LONGBLOB,

filename CHAR(50),

filesize CHAR(50),

filetype CHAR(50)

);

这是一个PHP示例:

// store.php3 - by Florian Dittmer

// Example php script to demonstrate the storing of binary files into

// an sql database. More information can be found at http://www.phpbuilder.com/

?>

Store binary data into SQL Database

// Code that will be executed if the form has been submitted:

if ($submit) {

// Connect to the database (you may have to adjust

// the hostname, username or password).

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

mysql_select_db("binary_data");

$data = mysql_real_escape_string(fread(fopen($form_data, "r"), filesize($form_data)));

$result = mysql_query("INSERT INTO binary_data (description, bin_data, filename, filesize, filetype) ".

"VALUES ('$form_description', '$data', '$form_data_name', '$form_data_size', '$form_data_type')");

$id= mysql_insert_id();

print "

This file has the following Database ID: $id";

mysql_close();

} else {

// else show the form to submit new data:

?>

File Description:


File to upload/store in database:

}

?>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值