Forum: Ruby mysql error handle

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
E8937c913f318c7f56da217e2263ce2a?d=identicon&s=25 Barabule Muci (bebitzaa)
on 2007-01-17 09:30
Hello,
I am making an connection with mysql
Mysql.real_connect("127.0.0.1","root","","f_juso","3306")

The problem is when the user and pass is correct it works very well but
when the user and pass is wrong it display the debugger and display the
message:
Mysql::Error in ComenziController#login
Access denied for user 'roots'@'localhost' (using password: NO)
and all that ruby debugger stuff.

I wan't to get the error in ruby and to display only my message like
"Invalid password."
It's help me, because i have made an login script and i wan't to check
the user and password by connecting on mysql with that user and
password.
Thanks
Ad7805c9fcc1f13efc6ed11251a6c4d2?d=identicon&s=25 Alex Young (regularfry)
on 2007-01-17 09:45
(Received via mailing list)
Barabule Muci wrote:
>
> I wan't to get the error in ruby and to display only my message like
> "Invalid password."
> It's help me, because i have made an login script and i wan't to check
> the user and password by connecting on mysql with that user and
> password.
> Thanks
>
Mysql::Error is an exception, so you should just be able to rescue it
and move on:

conn = nil
begin
   conn = Mysql.real_connect("127.0.0.1","root","","f_juso","3306")
   # do something with the connection
rescue Mysql::Error => e
   puts "Invalid password"
end
E8937c913f318c7f56da217e2263ce2a?d=identicon&s=25 Barabule Muci (bebitzaa)
on 2007-01-17 09:47
I try before but i get this message:

C:/work/aplicatie/app/controllers/comenzi_controller.rb:32: parse error,
unexpected kRESCUE, expecting kEND
       rescue Mysql::Error => e
             ^
C:/work/aplicatie/app/controllers/comenzi_controller.rb:32: parse error,
unexpected tASSOC
       rescue Mysql::Error => e
                             ^
C:/work/aplicatie/app/controllers/comenzi_controller.rb:43: parse error,
unexpected kEND, expecting $
Ee04bc0ca6dcdad4a7e8a8e1d4efb5d0?d=identicon&s=25 Michael W. Ryder (Guest)
on 2007-01-17 10:01
(Received via mailing list)
Barabule Muci wrote:
>
> I wan't to get the error in ruby and to display only my message like
> "Invalid password."
> It's help me, because i have made an login script and i wan't to check
> the user and password by connecting on mysql with that user and
> password.
> Thanks
>

Couldn't you create a separate account with a single table with only the
user names and passwords in it?  This way you can use a set login to
access this account and check if the user account is in the table.  If
it exists then check the password.  If the information is correct
continue with logging into the desired database otherwise display the
error message of your choice.
E8937c913f318c7f56da217e2263ce2a?d=identicon&s=25 Barabule Muci (bebitzaa)
on 2007-01-17 10:10
No i create users on mysql with rights on tables, this is why i chose
this metode.
Every user has a table that can acces.

Michael W. Ryder wrote:
> Barabule Muci wrote:
>>
>> I wan't to get the error in ruby and to display only my message like
>> "Invalid password."
>> It's help me, because i have made an login script and i wan't to check
>> the user and password by connecting on mysql with that user and
>> password.
>> Thanks
>>
>
> Couldn't you create a separate account with a single table with only the
> user names and passwords in it?  This way you can use a set login to
> access this account and check if the user account is in the table.  If
> it exists then check the password.  If the information is correct
> continue with logging into the desired database otherwise display the
> error message of your choice.
This topic is locked and can not be replied to.