2017-04-21 50 views
1

我有一个MSSQL数据库,其文件存储为blob,文件大小各不相同。我开发了一个概念验证并使用PHP的SQLSRV驱动程序,代码运行良好。我的客户需要应用程序在Linux环境中运行,所以我已经转移到FreeTDS,我似乎遇到的唯一问题是我使用的mssql_fetch_array函数没有检索整个blob。当我注意到存储在磁盘上的文件全部是63KB时,我将代码更改为保存二进制数据的变量var_dump,结果显示["attachment"]=> string(64512)与块的大小(数据库中的3,9mb)无关。使用PHP,MSSQL和FreeTDS将文件存储到磁盘

当我使用SQLSRV驱动程序时,我必须指定正在检索的数据是二进制文件,但我没有这些问题,但是,这始终失败。从我的代码摘录如下,请指出我的方法是错误的。

$stmt3 = mssql_query($tsql3) or 
      die("<p style='color:red;'>{addFile} Could not $query: " . mssql_get_last_message() . "</p>");; 

     // handle the notices with attachments, add meta and save binary info to filesystem 
     while ($noticeAttachmentList = mssql_fetch_array($stmt3)){ 

      $c = $noticeAttachmentList[1]; // filename 
      $header = $noticeAttachmentList[2]; // file header 
      $download = $noticeAttachmentList[3]; // binary data 
      $nID = $noticeAttachmentList[4]; // FK for external system  

      // create the filename path & make the filename web-friendly 
      $filename = $uploadsDir; 
      $filename .= str_replace(' ', '_',$c); 

      // create entry in notice_attachement table 
      $noticeFileInfo = array(
       'fk_notice_id'  => $noticeID, 
       'filename'   => $c, 
       'post_id'   => $postID, 
       'notice_attachment_id'   => $nID, 
       'date_added'    => date("Y-m-d H:i:s", time()) 

       ); 

      // check if the file exists 
      if (file_exists($filename)){ 
       echo "<p class='error'>Error: The file ".$filename." exists already in the destination folder.</p>"; 
       return false; 
      } 
      // create the file 
      if (!file_exists($filename)){ 
       echo "Your file, ". $filename ."is ready for download<br/>"; 
       // download the file from the database and store in uploadsDir 
       file_put_contents($filename, $download); 
       //var_dump($download); 
       return true; 
      } 

      $file = $metaAttachmentPath . str_replace(' ', '_',$c); 
} 

回答

1

有几个地方,这些限制可以发挥作用,但我猜它可能是在你的freetds的配置(通常在/etc/freetds.conf/etc/freetds/freetds.conf)。

查找类似这样的一行:

text size = 64512 

而在[global]部分改变它的东西是这样的:

test size = 4294967295 

这应该修复它的权利了 - 我相信默认设置在freetds.conf中是来自Sybase的传统[global]设置。

+1

你是一个拯救生命的人,非常感谢你! – Daniel