01.我们在Models中写数据库的操作。具体的查询代码如下:

<?php namespace App\Models\System;

use CodeIgniter\Model;

class User_model extends Model
{
    var $Db;

    function __construct()
    {
        parent::__construct();
        //创建数据库连接
        $this->Db = \Config\Database::connect();
    }

    function getdata()
    {
        //带参数条件查询
        $sql = "SELECT * FROM tp_user WHERE ( ID = ? AND ( MARK = ?))";
        $sqlrst = $this->Db->query($sql, array('143', '2019091500000143'));
        $rst = $sqlrst->getRow();
        return $rst;
    }

}

 

015.CI4框架CodeIgniter数据库操作之:Query带参数查询数

 

02. 在控制器调用的代码如下:

<?php namespace App\Controllers;

class Home extends BaseController
{
    // http://127.0.0.1/CI4/public/index.php/home/showdata

    var $User_Models;

    function __construct()
    {
        //创建数据库连接
        $this->User_Models = new \App\Models\System\User_model();
    }

    public function showdata()
    {
        $rst = $this->User_Models->getdata();
        ShowMessage($rst);
    }
}

015.CI4框架CodeIgniter数据库操作之:Query带参数查询数

 

 

03. 浏览器显示效果如下:

015.CI4框架CodeIgniter数据库操作之:Query带参数查询数

 

 

知识有价,如果您认为这篇文章有价值,认同作者的付出,可以微信二维码打赏任意金额给作者(微信号:382477247)哦,谢谢。

015.CI4框架CodeIgniter数据库操作之:Query带参数查询数

相关文章:

  • 2021-11-12
  • 2022-12-23
  • 2022-12-23
  • 2022-01-19
  • 2021-12-10
  • 2022-12-23
  • 2021-05-28
猜你喜欢
  • 2022-12-23
  • 2021-11-12
  • 2022-12-23
  • 2021-09-09
  • 2022-12-23
  • 2021-12-31
  • 2021-04-22
相关资源
相似解决方案