views:

31

answers:

2

I have some code as follows:

$query = <<<QUERY
SELECT
    *
FROM
    names
WHERE
    create_date > date('Y-m-d H:i:s');
QUERY

How can I put the date('Y-m-d H:i:s') in there without breaking out of the <<< statement?

+4  A: 

You could store that piece of code in a variable and use substitution.

$now = date('Y-m-d H:i:s');
$query = <<<QUERY
SELECT
    *
FROM
    names
WHERE
    create_date > $now;
QUERY;

(Example: http://www.ideone.com/pKSVF)

KennyTM
A: 

$date = date('Y-m-d H:i:s');
$query = <<<QUERY
SELECT
    *
FROM
    names
WHERE
    create_date > $date
QUERY

http://en.wikipedia.org/wiki/Here_document#PHP

mmattax