我正在为我们的客户编写代码,该代码旨在将图像从SQL Server数据库读取到缓存目录中的文件中。
二进制数据被截断为262144字节(256kb)。该列的类型为varbinary(max),我们使用ADOdb for Php来访问数据库。截断的原因是什么,我们如何防止它?
附件是用于执行连接的代码:
$conn_image = ADONewConnection('odbc_mssql');
$dsn = "Driver={SQL Server};Server=servername;Database=database;";
$conn_image->Connect($dsn,username,password);
$query = "SELECT
Personnel.Text4,
Images.Image
FROM Images
LEFT JOIN Personnel ON Images.ParentId = Personnel.ObjectId
WHERE Personnel.Text4 = '12345'
";
$result = $conn_image->Execute($query);
if (!$result)
print $conn_image->ErrorMsg();
else
while (!$result->EOF) {
if (!empty($result->fields[0])) {
$filename = $result->fields[0] . ".jpg";
$rawdata = $result->fields[1];
$size_to_write = strlen($rawdata);
$bytes_written = 0;
$file = fopen( "test" . DIRECTORY_SEPARATOR . $filename,'w');
while ($bytes_written < $size_to_write) {
$bw = fwrite($file, substr($rawdata, $bytes_written));
$bytes_written += $bw;
}
$result->MoveNext();
}
}