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};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();
}
}