【发布时间】:2014-07-16 21:07:51
【问题描述】:
使用 Python 的三引号字符串,我可以定义包含 '、反引号或 " 的字符串,而无需关心:
hello = """
This string is bounded by triple double quotes (3 times ").
Unescaped newlines in the string are retained, though
it is still possible to use all normal escape sequences.
Whitespace at the beginning of a line is
significant.
This string ends in a newline.
"""
在 PHP 中我可以使用 heredoc (<<<):
$str = <<<EOD
Example of string
spanning multiple lines
using heredoc syntax.
EOD;
我怎样才能在 MySQL 中做同样的事情?现在我必须确保我转义了我用来分隔的字符,例如如果我使用' 作为分隔符,我必须在我的字符串中使用\':
UPDATE article
SET article_text ='
Extra-virgin olive oil is a staple in any chef\'s kitchen.
'
我希望能够做到
UPDATE article
SET article_text ='''
Extra-virgin olive oil is a staple in any chef's kitchen.
'''
【问题讨论】:
标签: python mysql string language-comparisons mysql-escape-string