CI框架下PHP讀取mySQL數據庫


1.在application/config/database.php 中填寫好數據庫的相關內容 包括hostname username password database 等

2.新建一個文件 application/controllers/GuanliCon.php 

   代碼如下 

<?php

    class GuanliCon extends CI_Controller{

    public function __construct()

  {

     parent::__construct();

     $this->load->model('GuanliMo');
     $this->load->helper('url_helper');
   }
     public function view()

  {
     $this->load->view('customer-yonghuguanli');
   }
}
?>

3.新建一個文件 application/models/GuanliMo.php 

<?php
class GuanliMo extends CI_Model{
public function __construct()

{

   parent::__construct();

   $this->load->database();
}
public function Yonghu()

{
    $sql="select * from t_user";//sql 語句將建的表中全部內容讀取出來
    $query=$this->db->query($sql);
    $result=$query->result_array();
    return $result;//讀庫
}

}

 

 

    

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM