我正在尝试更新存储在MySql数据库中数据类型为BLOB的表中的个人资料图片。
当我检查我的表时它只是没有上传任何内容它在BLOB列中显示数据长度为零字节?我正在使用准备好的声明下面是否有我遗漏的内容?
最糟糕的部分是php文件也没有抛出任何错误所以我很困惑什么错了?
html
<form action="php/updateProfilePicture.php" method="post" data-ajax="false" enctype="multipart/form-data">
<label for="file">Profile Picture:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="Submit">
</form>
PHP
<?php
$con = mysqli_connect("localhost", "root", "root123", "xyz", "3306");
mysqli_select_db($con, "xyz");
$email = 'xyz@gmail.com';
$stmt = $con->prepare('UPDATE profileinformation SET Image = ? Where email = ? ');
$null = null;
$stmt->bind_param($null, $email);
$stmt->send_long_data(0, file_get_contents($_FILES['file']['tmp_name']));
$stmt->execute();
if ($stmt->errno) {
echo "FAILURE!!! " . $stmt->error;
}
else
echo "Updated {$stmt->affected_rows} rows";
$stmt->close();
?>
MySql中的profileinformation表
CREATE TABLE `profileinformation` (
`email` varchar(45) NOT NULL,
`Industry` varchar(100) DEFAULT NULL,
`Company` varchar(100) DEFAULT NULL,
`Phone` varchar(100) DEFAULT NULL,
`Fax` varchar(45) DEFAULT NULL,
`Address` varchar(200) DEFAULT NULL,
`Website` varchar(100) DEFAULT NULL,
`Image` blob,
PRIMARY KEY (`email`)
)
答案 0 :(得分:0)
如果你想知道预备语句中是否有错误,请执行以下操作:
if( $stmt = $con->prepare('UPDATE profileinformation SET Image = ? Where email = ? ');){
echo "statement is good";
}
else{
echo 'statement is bad';
我认为绑定参数应该是这样的错误:
//s is for binding strings
//i is for binding integers
// b is for blob
$stmt->bind_param('bs',$null, $email);
如果您想了解有关存储过程的更多信息,请点击此链接stored procedures
上面发布的这个链接提供了这个例子:
<?php
$stmt = $mysqli->prepare("INSERT INTO messages (message) VALUES (?)");
$null = NULL;
$stmt->bind_param("b", $null);
$fp = fopen("messages.txt", "r");
while (!feof($fp)) {
$stmt->send_long_data(0, fread($fp, 8192));
}
fclose($fp);
$stmt->execute();
?>
看起来您还没有设置传输速率参数