CodeIgniter Forums

Full Version: CI4 Tutorial Database Question
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
I'm new to CI, and I'm working through the CI4 tutorial.  I'm at the end of the news section, and the three entries I put in the database are not showing up in the view.  I see the output for no entries in the database.

How do I check the connection to the database to make sure there are no issues with it?  I pulled up PHPMyAdmin to look at the table, and it has the three entries I entered into it.

Thank you.
Did you configure ./app/Config/Database.php to setup you database server?
(11-27-2019, 06:55 PM)InsiteFX Wrote: [ -> ]Did you configure ./app/Config/Database.php to setup you database server?

I did.  I finally discovered my mistake.  A class wasn't coded correctly.  Thanks.
<?php namespace App\Models;

use CodeIgniter\Model;

class Blabla extends Model{

public function exfunc(){
$db = \Config\Database::connect();
$query = $db->query('SELECT blabla FROM blabla where blabla ');
$results = $query->getResultArray();
return $results;
}
}

A practise way for use database model in CI4.
@ProfessionalCoder,

CodeIgniter 4 Model already has the automatic database connection.
(11-30-2019, 05:28 AM)InsiteFX Wrote: [ -> ]@ProfessionalCoder,

CodeIgniter 4 Model already has the automatic database connection.


Thx I rewrite  $db to $this->db->query