UPDATE query with prepared statements

北城余情 提交于 2020-01-06 09:01:10

问题


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 :/


回答1:


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




回答2:


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:


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



来源:https://stackoverflow.com/questions/4056202/update-query-with-prepared-statements

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!