0

多くの html ファイルからテキストを 1 つのテキスト ファイル/変数にコピーしており、このデータ (基本的には html コード) を mysql データベースに挿入したいと考えています。mysql_real_escape_string を試しました。しかし、それはまだ機能していません。これは私がやっていることです:

$contentFromHtmlFile=file_get_contents($file);  
$all_html_content.=$contentFromHtmlFile; 
$all_html_content=mysql_real_escape_string($all_html_content);  
$insert_query = "insert into $databasetable (pdf_id,pdf_text_data) values (190,$all_html_content);";

mysql_query($insert_query) or die(mysql_error());

これはエラーです:

You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '<meta charset=\&quot;utf-8\&quot; />\n\n<div id=\&quot;jpedal\&quot; style=\&quo' at line 1

ここに挿入したいテキストのリンク: http://pastebin.com/F3BD745h

4

2 に答える 2

0

変数を一重引用符で囲み、それが文字列であることを示します (この場合):

$insert_query = "INSERT INTO $databasetable(pdf_id, pdf_text_data)
                 VALUES(190, '$all_html_content');";
                             ^                 ^

また、検索や同様の操作に文字列を使用する必要がない場合は、次のように通常の文字列に変換することをお勧めしますbase64_encode()

$contentFromHtmlFile = file_get_contents($file);  
$all_html_content .= $contentFromHtmlFile;  
$all_html_content = base64_encode($all_html_content);
$all_html_content = mysql_real_escape_string($all_html_content);  
于 2013-09-03T15:31:54.707 に答える