我有这个问题:
SELECT
`p`.*,
`a`.`name`,
(
SELECT
COUNT(`id`)
FROM
`accounts`
WHERE
`id` = 1
) AS `counter`
FROM
`participants` `p`
LEFT JOIN
`accounts` `a`
ON
`p`.`id` = `a`.`id`
WHERE
`p`.`id` = :id
我使用这个preg_match_all:
preg_match_all("/^(SELECT)(.+?)(FROM)/ims", $sql, $select, PREG_PATTERN_ORDER);
然后我得到了这个结果:
array(4) {
[0]=>
array(1) {
[0]=>
string(71) "SELECT SQL_CACHE
`p`.*,
`a`.`name`,
(
SELECT
COUNT(`id`)
FROM"
}
[1]=>
array(1) {
[0]=>
string(6) "SELECT"
}
[2]=>
array(1) {
[0]=>
string(61) " SQL_CACHE
`p`.*,
`a`.`name`,
(
SELECT
COUNT(`id`)
"
}
[3]=>
array(1) {
[0]=>
string(4) "FROM"
}
}
我对正则表达式没有好处。我希望获得SELECT
和FROM
之间的所有内容。
像这样:
`p`.*,
`a`.`name`,
(
SELECT
COUNT(`id`)
FROM
`accounts`
WHERE
`id` = 1
) AS `counter`
和
COUNT(`id`)
我该怎么做?