为什么调用now()会在php中失败[关闭]

Why does call to now() or current_timestamp() fail in simple php script?

<?php
try {
    echo "Now: " . CURRENT_TIMESTAMP() . "<br>";
    //echo "Time: " . time() . "<br>";

    echo "Done";
}
catch(Exception $e) {
    echo 'Message: ' .$e->getMessage();
}
?>

The script returns a blank page, and no error is reported. time() worked fine.

NOW() and CURRENT_TIMESTAMP() are MySQL functions, not PHP functions.

As this link suggests, the function you are looking for is date("Y-m-d H:i:s"). Here is the documentation

Your error should be something like

Call to undefined function CURRENT_TIMESTAMP()

CURRENT_TIMESTAMP is a synonym for CURRENT_TIMESTAMP() and NOW() and they are SQL functions, from what I know (maybe they also have meaning in other contexts).

As such, if that format is what you are looking for just do:

date("Y-m-d H:i:s");//like 2014-11-22 12:45:34

Also check this other SO question