Loading model and Connect to database
hi . i'm a newbie . I installed the web service. It worked properly. But I want to connect to the database through the model. At this time, a warning will be given. The text of the alert is as follows :
A PHP Error was encountered
Severity: Notice
Message: Undefined property: nn::$db
Filename: core/Model.php
Line Number: 77
Backtrace:
File: F:\wamp64\www\pizza2\web-service\application\models\read_information.php Line: 18 Function: __get
File: F:\wamp64\www\pizza2\web-service\application\controllers\nn.php Line: 36 Function: getAll
File: F:\wamp64\www\pizza2\web-service\application\libraries\REST_Controller.php Line: 688 Function: users_get
File: F:\wamp64\www\pizza2\web-service\index.php Line: 315 Function: require_once
how should i use of database and model ?
Sounds like your issue is having the webservice/site use a database. It is possiblt the web server you are using needs to have mysqli module installed. (if your using myslq) I was using a php apache docker container and had to create my own docker definition and install mysqli. Dockerfile.zip
Feel free to view the CodeIgniter framework's documentation. It describes how to configure a db https://codeigniter.com/docs
look . My problem is not having the ability to use of MySQL. My problem is connecting to the database. I use this web service. But I can not receive and upload data from MySQL.
My other problem is that I can't communicate with models. Can I connect to the model section(?) or should I write all the codes and the calculations inside the controller?
Hi @ghostmtn Create a Model let's say it as UserModel.php Now we want to access getUsers Method from the controller then $this->load->model('UserModel'); $this->UserModel->getUsers(); will give you the desired result
Hi @ghostmtn
Can you let me know whether you're able to connect to model using the above suggested code
Hi @ghostmtn
Did you loaded the database library properly? See How to connect to a database in CodeIgniter. "Undefined property nn:$db" seems the database library is not loaded.
please help me how to handle it
class Examination_mod extends CI_Model {
public $connection="";
function __construct() {
parent::__construct();
$this->connection=$this->load->database('muc', TRUE);
$connection=$this->connection;
}
//==========code for get process name =================//
public function student_detail(){
$userData=$this->session->userdata();
//print_r($userData['En_number']);
// die;
$ProfileData="ProfileData";
$Condotion="'$ProfileData'".','."'$userData[En_number]'".','."''".','."''".','."@P_Proc_Message".','."@P_Proc_Return";
$FetchData ="CALL Proc_EnrollmentNumber_Student($Condotion)";
//$FetchStudentData = $this->connection->query($FetchData);
//print_r($this->connection);die;
mysqli_next_result($this->connection);
print_r($StudentData);
die;
if(trim($StudentData['@P_Proc_Return'])=="success"){
$StudentDataCourseId = mysqli_fetch_assoc($FetchsqlData);
return $StudentDataCourseId;
}else{
//echo "fail";
}
}
} A PHP Error was encountered Severity: Warning
Message: mysqli_next_result() expects parameter 1 to be mysqli, object given
Filename: models/Examination_mod.php
Line Number: 37
Backtrace:
File: D:\Mukesh\TFS\MewarEMS\EMS\Dev\EMS\Muc\application\modules\student\models\Examination_mod.php Line: 37 Function: mysqli_next_result
File: D:\Mukesh\TFS\MewarEMS\EMS\Dev\EMS\Muc\application\modules\student\controllers\Examination.php Line: 46 Function: student_detail
File: D:\Mukesh\TFS\MewarEMS\EMS\Dev\EMS\Muc\index.php Line: 315 Function: require_once