SQLSTATE[HY000] [2005] Unknown MySQL server host ' ' (2) in Laravel

余生颓废 提交于 2019-12-11 21:49:37

问题


Hi I am making a simple login in laravel and I get an error when I try to perform an authentication. It is a rather odd connection error

Conection

'mysql' => array(
        'driver'    => 'mysql',
        'host'      => 'Marsur',
        'database'  => 'database',
        'username'  => 'root',
        'password'  => 'root',
        'charset'   => 'utf8',
        'collation' => 'utf8_unicode_ci',
        'prefix'    => '',
        'options'   => array(
            PDO::ATTR_PERSISTENT => true,
        ),
    ),

Controller

public function doLogin(){
    $rules = array('correo' => 'required|email',
                    'password' => 'required');

    $validator = Validator::make(Input::all(), $rules);
    if($validator->fails()){
        return Redirect::to('usuario')
                ->withErrors($validator)// manda los errores al login
                ->withInput(Input::except('password')); //

    }else{
        $userData = array(
                    'Correo' => Input::get('correo'),
                    'Contrasena' => Input::get('password')
                    );

        if(Auth::attempt($userData)){
            echo 'bien';
        }else{
            return Redirect::to('login');
        }
    }
}

Model*

class Usuario extends Eloquent{
protected $table = 'Usuario';
protected $primaryKey = 'idUsuario';
protected $fillable = array('Nombre', 
                        'Apellido', 
                        'TipoUsuario', 
                        'Contrasena', 
                        'Correo', 
                        'Telefono');
}

how can I fix it?


回答1:


Marsur is almost certainly not a valid hostname.

Generally a hostname is an IP address, or localhost. On some occasions you may refer to a remote server by its hostname, but in such a case it will have a name that looks like a web address.

So... fix that. If your database is on the same physical machine as the rest of your code, then you need localhost.



来源:https://stackoverflow.com/questions/23138414/sqlstatehy000-2005-unknown-mysql-server-host-2-in-laravel

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