CodeIgniter Forums
Model database Query - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forumdisplay.php?fid=28)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forumdisplay.php?fid=30)
+--- Thread: Model database Query (/showthread.php?tid=75660)



Model database Query - Endless05 - 03-02-2020

Hi, I'm using this code codeigniter 3.I try ci4 this code but not working.How work this code ci4?

Code:
public function give($from,$where=array()){
    $giveme = $this->db->from($from)->where($where)->get()->row_array();
    return $giveme;
}



RE: Model database Query - InsiteFX - 03-02-2020

It would be something like this:

PHP Code:
public function give($from,$where=array())
{
    $db = \Config\Database::connect();
    $builder $db->table($from);
    
    $giveme 
$builder->from($from)->where($where)->get()->getResultArray();

    return $giveme;


Did not have the time to test it, but give it a go.


RE: Model database Query - abatrans - 03-02-2020

If you use CI4 model, simply set the protected variables for $table, $returnType etc. then create function in the model:

PHP Code:
public function give$where=[] ) 
{
   return 
$this->where$where )->findAll();