场景:

将一个HTML页面存储到数据库中

问题:

HTML页面中既包含单引号也包含双引号

解决办法:

  1. 双单引号

    INSERT INTO table VALUES ('<html><script>let a=''a''</script></html>')
    
  2. 转义字符和 E

    INSERT INTO table VALUES (E'<html><script>let a=\'a\'</script></html>')
    

相关文章: