CodeIgniter数据库内联接



我的错误是您不关联两个数据库,信息不正确,所有查询都显示。我只想看到相应的查询, 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();
}

i修改未解决

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,

中添加选择。
$this->db->select('conjuge.id, conjuge.nome, conjuge.sobrenome, conjuge.cpf, conjuge.rg','users.user_id');
public function get_conjuge() {
}

然后用参数更改功能

public function get_conjuge($user_id) {
}

最新更新