CodeIgniter Forums
CI4 Tutorial Database Question - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter 4 (https://forum.codeigniter.com/forum-28.html)
+--- Forum: CodeIgniter 4 Support (https://forum.codeigniter.com/forum-30.html)
+--- Thread: CI4 Tutorial Database Question (/thread-74943.html)



CI4 Tutorial Database Question - tspowell001 - 11-27-2019

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.


RE: CI4 Tutorial Database Question - InsiteFX - 11-27-2019

Did you configure ./app/Config/Database.php to setup you database server?


RE: CI4 Tutorial Database Question - tspowell001 - 11-29-2019

(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.


RE: CI4 Tutorial Database Question - ProfessionalCoder - 11-30-2019

<?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.


RE: CI4 Tutorial Database Question - InsiteFX - 11-30-2019

@ProfessionalCoder,

CodeIgniter 4 Model already has the automatic database connection.


RE: CI4 Tutorial Database Question - ProfessionalCoder - 12-02-2019

(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