Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/264.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/59.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何在库CodeIgniter中获取用户ID_Php_Mysql_Codeigniter - Fatal编程技术网

Php 如何在库CodeIgniter中获取用户ID

Php 如何在库CodeIgniter中获取用户ID,php,mysql,codeigniter,Php,Mysql,Codeigniter,如何在库中获取用户ID 用户表 |ID |用户名| |---------------| |1 |亚历克斯| |2 |约翰| |3 |狮子座| |4 |帕卡特| 储物台 | ID | userID | store_picture | |-----------------------------| | 1 | Alex | img1.jpg | | 2 | Johey | img3.jpg | | 3 | Leos | img2.jpg | | 4 |

如何在库中获取用户ID

用户表

|ID |用户名| |---------------| |1 |亚历克斯| |2 |约翰| |3 |狮子座| |4 |帕卡特|

储物台

| ID | userID | store_picture |
|-----------------------------|
| 1  | Alex   | img1.jpg      |
| 2  | Johey  | img3.jpg      |
| 3  | Leos   | img2.jpg      |
| 4  | Pacat  | img5.jpg      |
libraries/Store.php

<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 

class Store 
{

    var $info=array();

    public function __construct() 
    {
        $CI =& get_instance();
        $site = $CI->db->select("userID,store_background")
        ->where("userID", 3)
        ->get("store_info");

        if($site->num_rows() == 0) {
            $CI->template->error(
                "You are missing the site settings database row."
            );
        } else {
            $this->info = $site->row();
        }
    }

}

?>

谢谢

请改用get_instance():

图书馆

<?php
    if ( ! defined('BASEPATH')) exit('No direct script access allowed'); 
    class Store { 
        public $info=array(); 
        public function __construct() { 
            $CI =& get_instance(); 
            $CI->load->model( 'Store_info_model' );
            $site = $CI->Store_info_model->get_userID( 3 );
            if($site->num_rows() == 0) { 
                //Do something when error happen
            } 
            else $this->info = $site->row();  
        } 
    } 
?> 

尝试在库中加载数据库或在配置中加载自动加载

将此添加到您的库中

$this->load->database();

你能举个例子吗,
$this->load->database();