Welcome Guest, Not a member yet? Register   Sign In
Need help about Query Bilder
#3

(08-28-2019, 04:53 PM)InsiteFX Wrote:
PHP Code:
$db      = \Config\Database::connect();
$builder $db->table($table);

// Get rows
$builder->where($arr)->get();

return 
$builder->getResultArray();

// Get row
$builder->where($arr)->get();

return 
$builder->getRow(); 

If you have the code in different methods you will need to use the top two lines
of code in each method.

Thank you for your response. I have another problem like this.  Could you please give me a solution on this? In CI 3 I used to write MY_Model like bellow:

CI 3 MODEL
PHP Code:
public function get_rows$table$arr ){
    $this->db->select()->from($table)->where($arr)->get();
    return $query->result();
}

public function 
order_row($by){
    $this->db->order_by($by'desc');
    return $this;


CI 3 CONTROLLER
PHP Code:
$data $this->my_model->order_row('column')->get_rows'my_table', array() ) 


I am trying this in CI 4 like bellow:

CI 4 MODEL
PHP Code:
public function getData$t$v ){
        $builder $this->db->table$t )->where$v )->get();
        return $builder->getRow(); 
}

public function 
orderData$by ){t;
        $this->db->orderBy$byDESC );
        return $this;


CI 4 CONTROLLER
PHP Code:
$m = new \App\Models\ManageModel();
$data $m->orderData'column')->getData'my_table', array() ); 

But this is producing ERROR:

Call to undefined method CodeIgniter\Database\MySQLi\Connection::orderBy()

How to solve this?
"Who thinks in code"
Perfectly describes who I am
mbparvez.me
Reply


Messages In This Thread
Need help about Query Bilder - by webdevron - 08-28-2019, 11:55 AM
RE: Need help about Query Bilder - by InsiteFX - 08-28-2019, 04:53 PM
RE: Need help about Query Bilder - by webdevron - 08-29-2019, 04:09 PM
RE: Need help about Query Bilder - by InsiteFX - 08-30-2019, 04:37 AM
RE: Need help about Query Bilder - by webdevron - 08-31-2019, 11:29 AM
RE: Need help about Query Bilder - by InsiteFX - 08-30-2019, 08:36 AM
RE: Need help about Query Bilder - by InsiteFX - 08-31-2019, 12:17 PM
RE: Need help about Query Bilder - by dave friend - 08-31-2019, 02:10 PM
RE: Need help about Query Bilder - by webdevron - 09-01-2019, 04:46 AM
RE: Need help about Query Bilder - by InsiteFX - 09-01-2019, 12:07 PM



Theme © iAndrew 2016 - Forum software by © MyBB