0

是否可以从 mysql (blob) 中选择图像,放入输入 (text) 然后保存到另一个 mysql (blob)?

感谢帮助。

4

2 回答 2

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);
于 2013-05-05T14:17:02.153 回答
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());
}
于 2013-05-05T19:09:10.157 回答