當我嘗試將博客條目添加到我的數據庫中時,我總是收到錯誤。我有一個簡單的語法高亮顯示器,但沒有顯示哪裏不對。PHP解析錯誤:語法錯誤,意外的T_OBJECT_OPERATOR,期待')'
錯誤: PHP Parse error: syntax error, unexpected T_OBJECT_OPERATOR, expecting ')' on line 75 and 71
我的腳本:
if(!isset($error)){
try {
//insert into database
$stmt = $db->prepare('INSERT INTO blog_posts (postTitle,postDesc,postCont,postDate) VALUES (:postTitle, :postDesc, :postCont, :postDate)') ; //line 71
$stmt->execute(array(
':postTitle' => $postTitle,
':postDesc' => $postDesc,
':postCont' => $postCont,
':postDate' => (new DateTime())->format('Y-m-d H:i:s') //Line 75
));
//redirect to index page
header('Location: index.php?action=posted&title='.$postTitle.'');
exit;
} catch(PDOException $e) {
echo $e->getMessage();
}
}
'(新的DateTime()) - >格式( 'Y-M-d H:I:S')'<---你在哪裏看到這樣的語法? – zerkms
[PHP解析錯誤:語法錯誤,意外的T \ _OBJECT \ _OPERATOR]的可能重複(http://stackoverflow.com/questions/13388541/php-parse-error-syntax-error-unexpected-t-object-operator) – mario
@zerkms這個語法存在於Laravel中,可能是OP試圖將框架邏輯應用到純php中。 – user2094178