0

i want to insert the contents of some text files into database, but it failed. please help me, thank you very much. :)

<?php

function saveContent($url){
set_time_limit(0);
   foreach ($url as $file =>$files) {
      $handle= fopen($files, "r") or die ('can not open file');
      $content = file_get_contents($files);

      //insert into database

      $q0 = mysql_query("INSERT INTO tb_document (doc_id, namefiles, content) VALUES('','$files','$content') ");
      fclose($handle);
   }
}

$path_to_check = 'C:/Appserv/www/textsumm2/textsumm/try/';
$url = glob($path_to_check.'*.txt');
$a = saveContent($url);

?>
4

2 回答 2

0

You have to escape the content of your files to prevent characters that cause an invalid SQL syntax.

You can use real-escape-string for that.

于 2012-06-01T07:49:58.660 回答
0

也许你可以使用 mysql_real_escape_string() :

$content = mysql_real_escape_string(file_get_contents($files));

于 2012-06-01T07:51:50.230 回答