2013-05-05 90 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()); 
} 
相關問題