[英]Inserting an image into sqlserver gives an “operand type clash”
I'm trying to save an image in a sql server 2000 database. 我正在尝试将图像保存在sql server 2000数据库中。 The data type of the column is image
. 列的数据类型为image
。
I get the following error: 我收到以下错误:
Error: Warning: odbc_exec() [function.odbc-exec]: SQL error: [Microsoft][ODBC SQL Server Driver][SQL Server]Operand type clash: text is incompatible with image, SQL state 22005 in SQLExecDirect in C:\\xampp\\htdocs\\test\\upload.php on line 25 Error, query failed 错误:警告:odbc_exec()[function.odbc-exec]:SQL错误:[Microsoft] [ODBC SQL Server驱动程序] [SQL Server]操作数冲突:文本与图像不兼容,SQLExecDirect中的SQL状态为22005,位于C:\\第25行的xampp \\ htdocs \\ test \\ upload.php错误,查询失败
Here is the code: 这是代码:
<?php
include('config.php');
if(is_uploaded_file($_FILES['userfile']['tmp_name']))
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$size = filesize($tmpName);
set_magic_quotes_runtime(0);//to desactive the default escape spacials caracters made by PHP in the externes files
$img_binaire = base64_encode(fread(fopen(str_replace("'","''",$tmpName), "r"), $size));
$query = "INSERT INTO test_image (image_name, image_content, image_size) ".
"VALUES ('{$fileName}','{$img_binaire}', '{$size}')";
odbc_exec($conn, $query) or die('Error, query failed');
echo "<br>File $fileName uploaded<br>";
echo "<br>File Size: $fileSize <br>";
}
?>
<?php
include('config.php');
$sql = "select * from test_image where id =2";
$rsl = odbc_exec($conn, $sql);
$image_info = odbc_fetch_array($rsl);
//$count = sizeof($image_info['image_content']);
//header('Accept-Ranges: bytes');
//header('Content-Length: '.$image_info['image_size']);
//header("Content-length: 17397");
header('Content-Type: image/jpeg');
echo base64_decode($image_info['image_content']);
//echo bindec($image_info['image_content']);
?>
What do I need to do differently? 我需要做些什么?
You have at least one error here: base64_encode(fread(fopen(str_replace("'","''",$tmpName), "r"), $size));
您在这里至少有一个错误: base64_encode(fread(fopen(str_replace("'","''",$tmpName), "r"), $size));
str_replace must be removed as it would spoil your data. 必须删除str_replace,因为它会破坏您的数据。
There can be other errors too. 也可能有其他错误。 you have to debug your code. 您必须调试您的代码。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.