【发布时间】:2018-02-14 07:10:10
【问题描述】:
我的错误是你没有关联两个数据库,信息不正确,出现所有查询。我只想看对应的查询,users.id = conjuge.id
$this->db->where('users.id', $user_id);
错误信息:未定义变量:user_id
型号:
class User_model extends CI_Model {
public function __construct() {
parent::__construct();
$this->load->database();
}
public function create_user($nome, $sobrenome, $username, $email, $password) {
$data = array(
'nome' => $nome,
'sobrenome' => $sobrenome,
'username' => $username,
'email' => $email,
'password' => $this->hash_password($password),
'created_at' => date('j-m-Y H:i:s'),
);
return $this->db->insert('users', $data);
}
public function resolve_user_login($username, $password) {
$this->db->select('password');
$this->db->from('users');
$this->db->where('username', $username);
$hash = $this->db->get()->row('password');
return $this->verify_password_hash($password, $hash);
}
public function get_user_id_from_username($username) {
$this->db->select('id');
$this->db->from('users');
$this->db->where('username', $username);
return $this->db->get()->row('id');
}
public function get_user($user_id) {
$this->db->from('users');
$this->db->where('id', $user_id);
return $this->db->get()->row();
}
private function hash_password($password) {
return password_hash($password, PASSWORD_BCRYPT);
}
private function verify_password_hash($password, $hash) {
return password_verify($password, $hash);
}
public function get_conjuge(){
$this->db->select('conjuge.id, conjuge.nome, conjuge.sobrenome, conjuge.cpf, conjuge.rg');
$this->db->from('conjuge');
$this->db->join('users', 'users.id = conjuge.id', 'inner');
$this->db->where('users.id', $user_id);
$query = $this->db->get();
return $query->result();
}
我修改没解决
public function get_conjuge($user_id){
$this->db->select('conjuge.id, conjuge.nome, conjuge.sobrenome, conjuge.cpf, conjuge.rg', 'users.id AS users');
$this->db->from('conjuge');
$this->db->join('users', 'users.id = conjuge.id', 'inner');
$this->db->where('users.id', $user_id);
$query = $this->db->get();
return $query->result();
}
遇到了 PHP 错误
严重性:警告
消息:缺少 User_model::get_conjuge() 的参数 1,调用 /home/planoser/public_html/oauth/application/controllers/User.php on 第 160 行并定义
文件名:models/User_model.php
遇到了 PHP 错误
严重性:通知
消息:未定义变量:user_id
文件名:models/User_model.php
【问题讨论】:
-
您没有将
$user_id传递给您的函数 -
您需要将
$userid传递给get_conjuge()函数,例如get_conjuge($userid)
标签: php mysql sql codeigniter inner-join