2014-11-09 00:39:02 12185次浏览 4条回答 1 悬赏 5 金钱

public function actionDel($id = NULL)

{
	$model = User::find()->where(['id' => $id])->one();
	
	if (!$model->delete())
	{
		echo 2;die;
	}
	echo 1;die;
}

1.数据库的这条数据删除成功了,两个echo 都没有执行到。页面居然报错,求解?
2.请求地址:http://localhost/yii2/backend/web/index.php?r=user/del&id=36
3.报错信息:
PHP Fatal Error – yii\base\ErrorException
Call to a member function delete() on a non-object

补充于 2014-12-26 00:09

请求地址:http://komeis.com/backend/web/index.php/quanwei/del?id=3
Database Exception – yii\db\Exception
SQLSTATE[42000]: Syntax error or access violation: 1142 DELETE command denied to user 'p22_handai'@'localhost' for table 'hd_quanwei'
The SQL being executed was: DELETE FROM hd_quanwei WHERE id=3

Error Info: Array
(

[0] => 42000
[1] => 1142
[2] => DELETE command denied to user 'p22_handai'@'localhost' for table 'hd_quanwei'

)


Caused by: PDOException
SQLSTATE[42000]: Syntax error or access violation: 1142 DELETE command denied to user 'p22_handai'@'localhost' for table 'hd_quanwei'

in /home/p22/public_html/komeis.com/vendor/yiisoft/yii2/db/Command.php at line 768

  • 回答于 2014-11-10 13:05 举报
    if($model !==null && !$model->delete()) {
        echo 2;die;
    }
    
    1 条回复
    回复于 2017-05-24 09:38 回复

    谢谢 兄弟 终于解决了

  • 回答于 2014-11-13 16:24 举报

    首先看你的错误信息: Call to a member function delete() on a non-object!
    就是说 调用的delete没有找到!并且 non-object 就是说没有该对象!
    请看楼上的回复试下看!没用的话 再跟帖!

  • 回答于 2015-05-21 14:11 举报

    哥们,找出原因了没?我也遇到这种问题!!求分享~~

  • 回答于 2015-08-26 17:13 举报

    我也是啊,求分享这问题

您需要登录后才可以回答。登录 | 立即注册
qq260101081
见习主管

qq260101081 广州

注册时间:2014-10-30
最后登录:2017-09-25
在线时长:13小时20分
  • 粉丝4
  • 金钱40
  • 威望10
  • 积分270

热门问题