从.txt文件中将html内容插入到mysql中

从.txt文件中将html内容插入到mysql中

问题描述:

I have 1000's of HTML newsletters all sequentialy numbered 1.txt 2.txt I am building a new cms way for staff to edit so I want the content in to the DB (mysql)

I was trying to run a bash script

array..

for i in "${array[@]}"

do

:

value=`cat ../data/"$i".txt`

mysql -u$MYUSER -p$MYPASS "cms" -se "UPDATE nl SET site_html = '$value', update_date=TIMESTAMP(NOW()) WHERE sid ='$i' "

done

but the html seems to explode the update statement

我有1000个 HTML code>简讯,所有序列编号为1.txt 2.txt I 我正在构建一个新的cms方式供员工编辑,所以我希望将内容输入到DB (mysql) code> p>

我试图运行bash脚本 p>

  array .. 
 
 for i in“$ {array [@]}”
 
do 
  code>  pre> 
 
 

: p>

  value =`cat ../data/"$i".txt`

mys​​ql -u $ MYUSER -p $ MYPASS“cms”-se“  UPDATE nl SET site_html ='$ value',update_date = TIMESTAMP(NOW())WHERE sid ='$ i'“
  code>  pre> 
 
 

完成 p>

但html似乎爆炸了更新语句 p> div>

You must double up (escape) the single-quotes in $value before you use it in the SQL string:

"UPDATE nl SET site_html = '${value//'/''}', update_date=TIMESTAMP(NOW()) WHERE sid ='$i' "

Otherwise any single quotes in the HTML cause the SQL string to terminate prematurely, which will certainly result in (SQL injection) syntax errors.