Datebase error mysqli::real_connect(): (HY000/2002): Connection refused codeingiter

拜拜、爱过 提交于 2021-02-05 10:39:27

问题


$active_group = 'default';

$query_builder = TRUE;

$db['default']['hostname'] = 'localhost';
$db['default']['username'] = '***********';
$db['default']['password'] = '***********';
$db['default']['database'] = '***********';
$db['default']['dbdriver'] = 'mysqli';
$db['default']['dbprefix'] = '';
$db['default']['pconnect'] = FALSE;
$db['default']['db_debug'] = TRUE;
$db['default']['cache_on'] = FALSE;
$db['default']['cachedir'] = '';
$db['default']['char_set'] = 'utf8';
$db['default']['dbcollat'] = 'utf8_general_ci';
$db['default']['swap_pre'] = '';
$db['default']['autoinit'] = TRUE;
$db['default']['stricton'] = TRUE;


$db['otherdb']['hostname'] = "101.53.153.40";
$db['default']['username'] = '***********';
$db['default']['password'] = '***********';
$db['default']['database'] = '***********';
$db['otherdb']['dbdriver'] = "mysqli";
$db['otherdb']['dbprefix'] = "";
$db['otherdb']['pconnect'] = FALSE;
$db['otherdb']['db_debug'] = FALSE;
$db['otherdb']['cache_on'] = FALSE;
$db['otherdb']['cachedir'] = "";
$db['otherdb']['char_set'] = "utf8";
$db['otherdb']['dbcollat'] = "utf8_general_ci";
$db['otherdb']['swap_pre'] = "";
$db['otherdb']['autoinit'] = TRUE;
$db['otherdb']['stricton'] = FALSE;

model

public function newusersignin()
{ 
    $db2 = $this->load->database('otherdb', TRUE);

    $firstName=$this->input->post('firstName');
    $lastName=$this->input->post('lastName');
    $timezone=$this->input->post('timezone');
    $fullname=$firstName.' '.$lastName;
    $email=$this->input->post('email');
    $phone=$this->input->post('phone');
    $ip_address=$this->input->ip_address();
    $institutional=$this->input->post('institutional');
    $pass=$firstName.mt_rand(1,100);
    $username=$email;
    $password=$this->hash($pass);
    $insertnewuser= array(
                        'name' =>$fullname,
                        'email'=>$email,
                        'phone'=>$phone,
                        'username'=>$username,
                        'password'=>$password,
                        'usertype'=>'ClgAdmin',
                        'create_date'=>date('y-m-d H:i:s'),
                        'create_userID'=>1,
                        'create_username'=>'example',
                        'systemadminactive'=>0,
                        'timezone'=>$timezone,
                        'status'=>1 
                    );
    $this->db->insert('admin',$insertnewuser);
    $adminid=$this->db->insert_id();
    $db2->insert('admin',$insertnewuser);

    $insertsettingnewuser= array('adminID' =>$adminid,'sname'=>$institutional,'phone'=>$phone,'address'=>"B-108,Sector 63, Noida",'email'=>$email,'automation'=>5,'currency_code'=>'INR','currency_symbol'=>'Rs.','footer'=>'Edge Technosoft Pvt. Ltd.','photo'=>'defualt.png','purchase_code'=>'f541d688-9d40-40db-99fb-65e6f80692ab','language'=>'english','theme'=>'Basic','fontorbackend'=>1,'updateversion'=>1,'attendance'=>'day' );
    $this->db->insert('setting',$insertsettingnewuser);
    $db2->insert('setting',$insertsettingnewuser);

    $alluserdata=0;
    if($adminid)
    {
        $user = $this->db->get_where('admin', array("username" => $username, "password" => $password,'status'=>1));
        $alluserdata = $user->row();
    }
    $i=1;

    if(count($alluserdata))
    {
        $userdata = $alluserdata;
        $array['permition'][$i] = 'yes';
    }
    else
    {
        $array['permition'][$i] = 'no';

    }
    if(in_array('yes', $array['permition']))
    {
        if($userdata->usertype == "ClgAdmin")
        {
            $settings = $this->setting_m->get_setting(array('adminID'=>$userdata->adminID));
            $lang = $settings->language;
            $data = array(
                "loginuserID" => $userdata->adminID,
                "name" => $userdata->name,
                "adminID" => $userdata->adminID,
                 "phone" => $userdata->phone,\
                "email" => $userdata->email,
                "usertype" => $userdata->usertype,
                "username" => $userdata->username,
                "photo" => $userdata->photo,
                "lang" => $lang,
                "adminpackage" =>$userdata->adminpackage,
                "totalstudent" =>$userdata->totalstudent
                "loggedin" => TRUE

            );

            $this->session->set_userdata($data);
             $sessionData = array(
                'session_id' =>session_id(),
                'ip_address'=>$ip_address,
                'last_activity'=>time(),
                'user_agent' => $this->input->user_agent(),
                'adminID'=>$userdata->adminID
            );   
            $this->db->insert('school_sessions',$sessionData);
            $pass1['pass']=$pass;
            $pass1['password']=$password;
            $pass1['adminID']=$userdata->adminID;
            return $pass1;
        }
    }
    else
    {
        return null;
    }
}

In the above code I am cresting two database file one for localhost and another for IP. Where it's working for localhost and all data are save but in case of ip it show nothing in my database and it throw an error i.e.

Message: mysqli::real_connect(): (HY000/2002): Connection refused

How can we fix this?


回答1:


for other db you need to set with same name.so please correct with following code

$db['otherdb']['username'] = '***********';
$db['otherdb']['password'] = '***********';
$db['otherdb']['database'] = '***********';


来源:https://stackoverflow.com/questions/60501299/datebase-error-mysqlireal-connect-hy000-2002-connection-refused-codeingi

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!