php mssql2000 text字段 被截断读取不完整的问题解决方法
在抓取页面的时候保存源文件是很好的习惯,如果有需要可以照旧重新抓取,页面文件平均1W字节左右,于是使用了text字段
问题:text读取不完全
解决方法:$sql="SET TEXTSIZE 2147483647";
测试代码:
<?php /*sql create CREATE TABLE [VOD_TMP_DATA] ( [id] [int] IDENTITY (1, 1) NOT NULL , [movie_list_tmp_name] [varchar] (500) COLLATE Chinese_PRC_CI_AS NULL , [movie_list_tmp_data] [text] COLLATE Chinese_PRC_CI_AS NULL , [movie_url_1_tmp_name] [varchar] (500) COLLATE Chinese_PRC_CI_AS NULL , [movie_url_1_tmp_data] [text] COLLATE Chinese_PRC_CI_AS NULL , [movie_url_2_tmp_name] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL , [movie_url_2_tmp_data] [text] COLLATE Chinese_PRC_CI_AS NULL ) ON [PRIMARY] TEXTIMAGE_ON [PRIMARY] GO */
$host="192.168.137.199,1433";$sa="sa";$pwd="sasa"; $dbh_4 = new PDO('mssql:host='.$host.';dbname=[MY_DB]',$sa,$pwd); $save_tmp_file="../tmp_movie_list.txt"; $save_tmp_file1="tmp_movie_list.txt"; $fp1=fopen($save_tmp_file,"r"); $buffer=fread($fp1,filesize($save_tmp_file)); $buffer_base64=base64_encode($buffer); $buffer_base64_strlen= strlen($buffer_base64); fclose($fp1); echo $buffer_base64."<br />"; echo $buffer_base64_strlen."<br />"; $sql="SET TEXTSIZE 2147483647"; $dbh_4->query($sql)or die("err<br />"); echo "setTEXTSIZE_ok<br />"; $sql="INSERT INTO [MY_DB].[dbo].[VOD_TMP_DATA]( [movie_list_tmp_name], [movie_list_tmp_data]) VALUES('".$save_tmp_file1."','".$buffer_base64."') "; $dbh_4->query($sql)or die("err<br />"); echo "install_ok<br />";
$sql="SELECT [movie_list_tmp_data] FROM [MY_DB].[dbo].[VOD_TMP_DATA] WHERE [movie_list_tmp_name]='tmp_movie_list.txt';"; foreach($dbh_4->query($sql) as $row_4){ echo "<pre>"; echo print_r($row_4); echo "</pre>"; echo strlen($row_4[0])."<br />";
$sql='DELETE FROM [MY_DB].[dbo].[VOD_TMP_DATA]'; $dbh_4->query($sql)or die("err<br />"); echo "del_ok<br />"; } ?>
参考前辈们的文章:
http://blog.csdn.net/chris_mao/article/details/2023762