且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Laravel Raw DB插入受影响的行

更新时间:2022-05-02 22:47:02

您可以使用此功能:

int affectingStatement (字符串$ query,数组$ bindings = array())

int affectingStatement(string $query, array $bindings = array())

运行一条SQL语句并获取受影响的行数.

Run an SQL statement and get the number of rows affected.

参数

  • 字符串$ query
  • 数组$ bindings

返回值

  • int

laravel 4.2 也已经记录了此功能至于 5.4 .

This function is already documented for laravel 4.2 as well as for 5.4.

请注意,insert()statement()的别名,并且将返回布尔值.而功能update()delete()affectingStatement()的别名.因此,如果您想变得有趣并引起审阅者的困惑,您也可以写$rowCount = DB::delete("INSERT IGNORE ...", $bindings)-它会起作用.

Note that insert() is an alias for statement() and will return a boolean. While the functions update() and delete() are aliases for affectingStatement(). So if you want to be funny and confuse the reviewers you could also write $rowCount = DB::delete("INSERT IGNORE ...", $bindings) - and it will work.