Peiris
asked on
Saving a pdf file in to MSSQL database
Hi,
I am using Zend_File_Transfer_Adapter _Http to upload a file to server and then use the file_get_contents to read the contents and encode using base64 to save to mssql database.
to save I am using a class that extends Zend_Db_Table_Abstract.
The question is, when this code runs, it take supper long time to save the contents in to the database. The database is MSSQL. Document Content filed is set as varchar(MAX).
any idea what is happening here..
thanks
Peiris
I am using Zend_File_Transfer_Adapter
$tmpContnets = file_get_contents($filename, FILE_USE_INCLUDE_PATH);
$filecontent = base64_encode($tmpContnets);
$newFileInfo['intDocSectionId'] = $fileSection;
$newFileInfo['intDocSize'] = $sizeOfFile;
$newFileInfo['strDocType'] = $filemimetype;
$newFileInfo['strDocName'] = $displayFileName;
$newFileInfo['strDocContents'] = $filecontent;
$newFileInfo['datDocCreated'] = gmdate('Y-m-d H:i:s');
$newFileInfo['intDocCreatedBy'] = $user->userid;
$newFileInfo['strExt'] = $docext;
$newDoc->putNewDocument($newFileInfo)
to save I am using a class that extends Zend_Db_Table_Abstract.
class ABC_DbTable_Documents extends Zend_Db_Table_Abstract {
protected $_schema = 'Accounts.dbo';
protected $_name = 'tDocuments';
protected $_primary = 'intDocId';
public function putNewDocument(array $newDocument) {
try {
$newRow = $this->createRow($newDocument);
$newRow->save();
return true;
} catch (Exception $e){
Log::error(get_class(), __LINE__, $e->getMessage(), true);
return false;
}
}
The question is, when this code runs, it take supper long time to save the contents in to the database. The database is MSSQL. Document Content filed is set as varchar(MAX).
any idea what is happening here..
thanks
Peiris
What version of SQL Server are you using? If it's 2012 take a look at the File Table feature, which is a way of keeping files under the thumb of the database management system without ever actually reading them in to tables.
hth
Mike
hth
Mike
I do not know MSSQL but I do know MySQL. In MySQL you do not store binary in a VARCHAR but you use a BLOB or a LONGBLOB. Might be the same for MSSQL. Hope this helps.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I have found a solution.
If none of these things have any measurable effect on response time, then you might want to look at using YSlow to see if the overall script is just slow. That happens sometimes with frameworks.