Hi,
I'm using Doctrine 1.1.2 as my ORM framework in combination with Zend Framework and a MSSQL server back-end. What I am trying to do is to store a blob to the database, but Doctrine is throwing me errors when I try. The column in the database is of type varbinary(max), and the model in Doctrine is configured as follows:
$this->hasColumn('binary_data', 'blob', null, array(
'type' => 'blob',
'notnull' => false,
'primary' => false,
'autoincrement' => false,
));
This is generated with Doctrine::generateModelsFromDB, and should be correct. The source of the blob is a file upload. I have verified that the file upload succeeds, and that I am able to print the binary data (shows as a bunch of garbled data).
When I try to save the binary data by using the Doctrine model, I get different error messages based on what I do. I have so far tried this (probably some more too that I don't remember):
// Error:SQLSTATE[HY000]: General error: 10007 Incorrect syntax near '%PDF-1.5 %µµµµ...
$model->binary_data = fread(fopen($_FILES["file"]["tmp_name"], 'r'), filesize($_FILES["file"]["tmp_name"]));
$model->save();
---
// Error: same as above
$fileHandle = fopen($_FILES["file"]["tmp_name"], "r");
$fileContent = fread($fileHandle, filesize($_FILES["file"]["tmp_name"]));
$model->binary_data = $fileContent;
$model->save();
---
// This should work on 1.2, but I have 1.1.2
// Error: Validation failed in class Clazz 1 field had validation error: * 1 validator failed on binary_data (type)
$model->binary_data = file($_FILES["file"]["tmp_name"]);
$model->save();
This should be straight forward, but I just can't figure out what I'm doing wrong.