php unexpected t_object_operator,PHP解析錯誤:語法錯誤,意外的T_OBJECT_OPERATOR,期待')'...

在尝试将博客条目插入数据库时遇到PHP解析错误,具体为'PHP Parse error: syntax error, unexpected T_OBJECT_OPERATOR, expecting ')'。问题出现在第71行的INSERT INTO语句以及第75行的新日期格式化。解决方案可能涉及检查PHP语法,特别是对象操作符的使用,确保正确关闭括号。同时,考虑代码是否适应纯PHP环境,因为该语法可能源于Laravel框架。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

當我嘗試將博客條目添加到我的數據庫中時,我總是收到錯誤。我有一個簡單的語法高亮顯示器,但沒有顯示哪裏不對。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();

}

}

2014-04-10

Locke

+1

'(新的DateTime()) - >格式( 'Y-M-d H:I:S')'

+0

[PHP解析錯誤:語法錯誤,意外的T \ _OBJECT \ _OPERATOR]的可能重複(http://stackoverflow.com/questions/13388541/php-parse-error-syntax-error-unexpected-t-object-operator) –

+0

@zerkms這個語法存在於Laravel中,可能是OP試圖將框架邏輯應用到純php中。 –

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值