UPDATE query with prepared statements

2019-09-05 23:05发布

Having problems with and update query i keep getting

Warning: Crud::update() [crud.update]: Property access is not allowed yet in crud.php on line 60

This is my code

$stmt = $this->mysql->prepare('UPDATE links SET title = ?, url = ?, comment = ? WHERE id = ?');
$stmt->bind_param('sssi',$title,$url,$comment,$id);
$stmt->execute();
$stmt->close();
on line 60 return $stmt->affected_rows;

Googled it and only found one reference in the php documentation in a comment but i couldn't understand the comment :/

3条回答
Fickle 薄情
2楼-- · 2019-09-05 23:10

Do you want

$stmt->affected_rows();

vs.

$stmt->affected_rows;

?

I'm not sure.

Otherwise you can check to confirm that there was no mysql error first before checking the affected rows.

查看更多
兄弟一词,经得起流年.
3楼-- · 2019-09-05 23:11

The problem was that i used $stmt->close(); before using $stmt->affected_rows; silly error really. thats what i get for late night coding.

查看更多
何必那么认真
4楼-- · 2019-09-05 23:22

are you sure the stament returns true? this error occurs if the statement was not prepared properly, or not prepared at all, according to php documentation.

"To prevent this, always ensure that the return value of the "prepare" statement is true before accessing these properties."

Hope this helps cheers

查看更多
登录 后发表回答