How do I stop varbinary data from being truncated to 256kb when reading from an SQL Server database using adodb for php
I am writing code for a client of ours which is designed to read an image from a SQL Server database into a file in a caching directory.
The binary data is being truncated at 262144 bytes (256kb). The column is of type varbinary(max), and we are using the ADOdb for Php to access the database. What is the cause of the truncation, and how do we prevent it?
Attached is code used to perform the connection:
$conn_image = ADONewConnection('odbc_mssql');
$dsn = "Driver={SQL Server};S开发者_Python百科erver=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();
}
}
If you're still on SQL Server 2000 you need to deal with BLOBs like this. Regardless, using the reader.GetBytes()
method is likely what you're looking for. Microsoft provides an example here.
With ADOdb you can open up the adodb.inc.php file and you'll see the line:
var $maxblobsize = 262144;
You can change it to be a greater value.
精彩评论