0

i'm using laravel with oracle database. Now, i'm making login sections. When i was input correct username and password, result is okay. But i was input incorrect username or password, following exception occured:

Illuminate \ Database \ QueryException

oci_error() expects parameter 1 to be resource, object given (SQL: select * from test_laravel_auth where username = tugsuu and password = testsss)

My controller code:

$user = DB::table('test_laravel_auth')->where('username', '=', $input['login_username'])
                                                    ->where('password', '=', $input['login_password'])
                                                    ->get();
            return count($user);
            if($user != null){
                return "SUCCESS :D";
            }
            return "failed";

4 Answers 4

1

I assume you were using [jfelder/Laravel-OracleDB] package. It is a known issue as stated on site and a fixed was already added. Try updating your packages by running composer update.

Another option is to use yajra/laravel-oci8 package to connect to Oracle.

Sign up to request clarification or add additional context in comments.

Comments

0

try this

$user = DB::table('test_laravel_auth')->where('username', '=', Input::get('username'))
          ->where('password', '=', Input::get('password'))
          ->get();

    if(Auth::attempt($user)) 
    {
    //here success    
    }
    else
    {
     return Redirect::to('login')->with('login_errors','Invalid Login Credentials.');
    }

4 Comments

Try your solutions. Then following error occured: Illuminate \ Database \ QueryException oci_error() expects parameter 1 to be resource, object given (SQL: select * from test_laravel_auth where username= 16 and password = test)
Auth::attempt() takes an array, NOT an object, thus above code will not work. You need to use Auth::login($user) to login in a user from a user object. Alternatively you can use Auth::loginUsingId(1).
$userData = array('username'=>11, 'password'=>123); Okay, Auth::attemps($userData) - this is running fine, But if my inserted username exists on db, other failed following exception occured: lluminate \ Database \ QueryException oci_error() expects parameter 1 to be resource, object given (SQL: select * from test_laravel_auth where username= 16 and password = test) 16 doesn't exists on my DB.
Try my solution above.
0

I suggest you use first instead of get(), this will retrieve the first record (only one should be found). You could also try with firstOrFail() and create an error handler if it "fails". If it fails = login incorrect.

$user = DB::table('test_laravel_auth')->where('username', '=', Input::get('login_username'))->where('password', '=', Input::get('login_password'))->first();

if (!is_null($user))
{
   Auth::login($user);
}
else
{
    //failed
}

Comments

0

Im also using Oracle database in Laravel and this solution works for me:

if ( Auth::attempt( array( 'user_name' => Input::get( 'username' ), 'password' => Input::get( 'password' ) ) ) )
{
    return Redirect::intended( 'dashboard' );
}
else
{
    return Redirect::to( 'login' )->withInput( Input::except( 'password' ) );
}

My code is just same on the Laravel documentation. It doesn't require you to use queries for authentication, all you need to use is the authentication class that comes with Laravel.

What driver/package you are using? Im using the yajra/laravel-oci8 package to make Oracle work with Laravel. You may read more about laravel-oci8 package documentation on its page: https://github.com/yajra/laravel-oci8

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.