php - Laravel Eloquent 更新受影响的行数始终为 1

标签 php mysql laravel laravel-5 eloquent

我是 Laravel 新手。我面临的问题是,

When I tried to update a column in table with same data using laravel eloquent the affected rows gives me always 1.

这是我运行更新时运行的查询:

update `table` set `updating_column` = 1, `updated_at` = 2016-09-17 15:56:53;

在上面的查询中,laravel 更新 updated_at 列以及我请求更新的列。

这就是为什么我总是有 1 行受到影响。

有没有办法在没有 updated_at 列的情况下获取实际受影响的行。

编辑:

$modelobj = new Model();
$aftcnt = $modelobj->where(['ssnid'=>Session::get('SSNID')])
                   ->update([updating_column'=>1]);

当我总是刷新页面时,变量$aftcnt给我1。

最佳答案

对于 Laravel 5

您可能会看到获取受影响行的示例

$ids=[10,20,30,40];

$affectedRow=DB::update('update users set is_archive = 1, status=0 where id != ?', $ids);

echo $affectedRow;
exit;

关于php - Laravel Eloquent 更新受影响的行数始终为 1,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39545965/

相关文章:

php - 完成抽象类的常见做法是什么?

php - mysql_result 在 php 中导致错误

MySQL正在做全表筛选

php - 在 Codeigniter 中更新用户详细信息

用于复制数据库及其所有表的 PHP 脚本

mysql - 如何更新名称与 SQL 格式匹配的表的行

php - 错误 : Your requirements could not be resolved to an installable set of packages. Laravel

php - Illuminate\Database\Eloquent\Model::setAttribute() Laravel 4.1 缺少参数 2

laravel - 如何在 Laravel Mix 中使用 FullCalendar

php - register_shutdown_function() 和 die()