php - Laravel - PDO - 更新

标签 php mysql sql laravel pdo

好吧,当我在我的本地主机上运行时,PDO 代码完美无缺,但是当我 在我的主机上运行不起作用,并给我一个错误

Connection.php 第 651 行中的 QueryException: SQLSTATE[HY000]: 一般错误: 2053 (SQL: UPDATE roles SET member_id=76446,member_role=5613 WHERE member_id=76446)

代码是

if (!empty($member->id)) {



        $new_id = $member->id;

        $new_p = $member->p_id;

        $sql = "UPDATE roles SET member_id=$new_id,member_role=$new_p WHERE member_id=$new_id";

        $member = DB::select($sql);

        Session::flash('sm', 'Thank you! You have edited the Profile successfully!');

    }

感谢帮助!

最佳答案

Laravel 内置 query builder 所以你的代码应该是这样的 -

if (!empty($member->id)) {

        $new_id = $member->id;

        $new_p = $member->p_id;

        DB::table('roles')->where('member_id', $new_id)->update(['member_role' => $new_p]);

        Session::flash('sm', 'Thank you! You have edited the Profile successfully!');

    }

我删除了 member_id=$new_id 因为您已经在 where 子句中检查了这部分

关于php - Laravel - PDO - 更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34774056/

相关文章:

MySQL Where IN 数组

php - 如何将 jQuery/AJAX 结果放入表格单元格

mysql 存储过程动态Where 子句

mysql - 选择 SQL 查询 FROM 表,选择使用该查询?

mysql - Magento MySQL 调整

MySQL(存储)过程 - 参数和查询

SQL 很好地检索树结构

php - 使用最少的资源使用数据库检查唯一的随机值

php - 如何在模型中使用带有枚举集合列表和更改集合的 Lithium PHP 框架

javascript - 尝试将 javascript 变量用作 php 变量并将其存储在 mysql 中