导入带有html代码的mysql表时出现语法错误

Cad*_*adz 6 mysql import mysqlimport

我试图导入一个mysql表,其中包含html代码的数据,它会生成语法错误.有人能告诉我如何用html代码正确导入mysql

Sytanx错误:

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 ''<ul>\r\n<li>Unpack the equipment and materials</li>\r\n<li>Secure the mounting '
Run Code Online (Sandbox Code Playgroud)

Mar*_*ker 5

通过极少数你向我们展示了错误,我可以看到它正在抱怨胭脂单引号 '

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 ''<ul>\r\n<li>Unpack the equipment and materials</li>\r\n<li>Secure the mounting '
Run Code Online (Sandbox Code Playgroud)

如果你在MySQL的引用文本的开头就注意到了它,''并且最后只有'MySQL错误在单引号的开始位置显示问题代码,所以我们删除一个包含我们最终的错误语法的单引号

'<ul>\r\n<li>Unpack the equipment and materials</li>\r\n<li>Secure the mounting

所以它抱怨一个单引号<ul>.在将数据输入数据库之前,你需要确保你的HTML是安全的,所以要替换单引号,\'如果它应该被渲染你应该使用&#39;

如果你使用php,你可以用它addslashes来逃避任何单一的引号'\'入口之前.

另一个选择是停止使用直接构造的查询,并在连接器中使用prepare&bind_param,因为这样可以防止这种情况发生.

然而不幸的是,如果你正在使用mysqlimport cli并且这是一个预构建的.sql文件,你必须手工完成并修复它我强烈推荐一个语法启用编辑器来做这个MySQL工作台它最适合MySQL语法