Welcome Guest, Not a member yet? Register   Sign In
Sql in Model - Undefined variable: db
#1

This is my symple model:

<?php namespace App\Models;

use CodeIgniter\Model;


class banner extends Model {

$query_ = "SELECT img_banner FROM tab_4 WHERE m = 12";

$query = $db->query($query_);

return $query->getResultArray();

}

?>

I receive this error: Undefined variable: db

Which is the correct way for resolve the issue?
Reply
#2

https://codeigniter.com/user_guide/datab...cting.html

You have to define db , its in the doc
Reply
#3

Inside the Model:
PHP Code:
$db $this->db

Outside:
PHP Code:
$db db_connect(); 
Reply




Theme © iAndrew 2016 - Forum software by © MyBB