我得到了解析错误。 我使用mysql查询表达式在heredoc中以正则表达式传递变量?
$sql = <<<SQL
SELECT
name,
full_code
FROM M_CATEGORY
WHERE full_code REGEXP '^00'.$var.'[0-9][0-9][0-9]$'
ORDER BY full_code ASC
SQL;
最初的代码是
$sql = "
SELECT
name,
full_code
FROM M_CATEGORY
WHERE full_code REGEXP '^00".$var."[0-9][0-9][0-9]$'
ORDER BY full_code ASC";
答案 0 :(得分:2)
$sql = <<<SQL
SELECT
name,
full_code
FROM M_CATEGORY
WHERE full_code REGEXP '^00{$var}[0-9][0-9][0-9]$'
ORDER BY full_code ASC
SQL;
请阅读有关heredoc:http://php.net/manual/ru/language.types.string.php#language.types.string.syntax.heredoc
的信息