• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Call to undefined method Builder::affectedRows()

#1
in the documentation - affectedRows();
Quote:Displays the number of affected rows, when doing “write” type queries (insert, update, etc.).
My code:

PHP Code:
// Method in model
function editClient($id ''$FIELDS = [])
{
    
$db $this->db->table('WK_clients');

    
$db
        
->where('id', (int)$id)
        ->
update($FIELDS);

    
$FIELDS['id'] = $id;

    return 
$db->affectedRows() ? $FIELDS false;

As a result, I get the error:
Call to undefined method CodeIgniter\\Database\\MySQLi\\Builder::affectedRows()

Please tell me what I'm doing wrong.
Reply

#2
Have you tried :
$this->db->affectedRows()
instead of :
$db->affectedRows()
Reply

#3
This is how it works. Not very logical. If you work with Query Builder Class, then these methods should also be there, at least you can just make a mistake. And this also applies to the method -> insertID ()
Reply

#4
You're right !

An other solution is :
the method update() should return FALSE if failure and the number of affected rows if success

The signature of the method would be :
public function update($withAffectedRows = FALSE)

It's better with a parameter because we don't always want the number of affected rows and it costs a query ...

My mistake, the method affectedRows() doesn't perform a database query ...
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.