Php 如何在库CodeIgniter中获取用户ID
如何在库中获取用户ID 用户表 |ID |用户名| |---------------| |1 |亚历克斯| |2 |约翰| |3 |狮子座| |4 |帕卡特| 储物台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 | 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();