Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

mani95lisa's avatar

What's the best way to handle sql error, as validation error?

For example, I can use validator for user register. But if I set username column is unique, when it passed validate then will got a sql error caused by unique.

I know I can use try catch to catch that error, but how can I got the errors like $this->validate() method failed return?

Thanks!

0 likes
3 replies
jlrdw's avatar

Query the database to see if that username is already in use, if so, display a message to user to select another name.

Please or to participate in this conversation.