• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Working with Database in CI4 (for New Members)

#1
Tongue 
Connect to Database
Code:
- in Model
$db = $this->db;
- not in Model
$db = db_connect();

Process Query
Code:
- with Query
$sql  = "Your query here";
$query = $db->query($sql);
- with Builder
$builder = $db->table("Your table name here");
$query  = $builder->getWhere($arrWhere, $limit);
$query  = $builder->insert($arrInsert);
$query  = $builder->update($arrUpdate, $arrWhere);

Check Result with $db->query and $bulder->getWhere
Code:
if (count($query->getResult()) > 0) {
foreach ($query->getResult() as $row)
{

}
or
$row = $query->getRow();

// Yes have data
// Code here
}

... and read more in User Guide...
and any comment for add...

Learning CI4 from my works, from errors and how to fix bugs in the community

Love CI & Thanks CI Teams

Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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