2013-05-05 94 views

回答

1

是的,这是可能的。二进制字符串将保存数据就好了。

编辑:下面是一个例子

CREATE TABLE fooblob (
    id INT AUTO_INCREMENT , 
    data MEDIUMBLOB, 
    PRIMARY KEY (id) 
) ENGINE = InnoDB; 

$dbh = mysqli_connect('localhost', 'my_user', 'my_password', 'world'); 
# Read a blob 
if(!$res = mysql_query("SELECT data FROM fooblob WHERE id = 1", $dbh)) { 
    die("ERROR: " . mysql_error()); 
} 
$row = mysql_fetch_assoc($res); 
$data = $row['data']; 

# Write it to a different row (pretend it's a different table) 
$stmt = mysqli_prepare($dbh, "INSERT INTO fooblob(data) VALUES (?)"); 
mysqli_stmt_bind_param($stmt, 's', $data); 
mysqli_stmt_execute($stmt); 
+0

这是怎么回事? – 2013-05-05 17:12:11

0

可以这样吗?

1)

$dbh = mysqli_connect('localhost', 'my_user', 'my_password', 'world'); 
# Read a blob 
if(!$res = mysql_query("SELECT data FROM fooblob WHERE id = 1", $dbh)) { 
    die("ERROR: " . mysql_error()); 
} 
$row = mysql_fetch_assoc($res); 
$data = $row['data']; 

2)

<textarea name="test" id="test"><?= $data ?></textarea> 

3)

$post_data = $_POST['test']; 
$dbh = mysqli_connect('localhost', 'my_user', 'my_password', 'world'); 
if(!$res = mysql_query("INSERT INTO fooblob (data) VALUES ('$post_data') WHERE id = 1", $dbh)) { 
    die("ERROR: " . mysql_error()); 
} 
相关问题