Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6932257
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T11:40:58+00:00 2026-05-27T11:40:58+00:00

If you have properly defined checks and assertions in your DB (e.g., MySQL), is

  • 0

If you have properly defined checks and assertions in your DB (e.g., MySQL), is it good practice or even worth validating data before you update or insert a record into a DB like MySQL?

From what I see, as long as the checks you have to perform are not complicated and can be accomplished by the DB itself, it looks wasteful to validate the data in say… PHP first and THEN MySQL again.

Am I correct on this?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T11:40:59+00:00Added an answer on May 27, 2026 at 11:40 am

    As a general rule, you should do validation as soon as possible. This means in your PHP code in this case. Why?

    1. It’s more efficient. Why send data to the database (which might be over a network, or even in a different country) if it’s only going to respond with an error? Better to avoid the error first.

    2. It makes it much easier to report a useful/friendly error message to your user. Sometimes it might be possible to parse a DB error sufficiently to generate a useful error message, but most DB errors don’t look very friendly to end-users. It’s better to generate the error as close to the user as possible.

    Now, even with this, it’s still good to have checks in your DB, but they should act as a last resort, and when your DB throws an error, it should be considered a bug, not a “data validation feature.” In other words, if you ever get a DB exception, it’s an indication that your PHP code is broken.

    Exception: There was one time recently when I chose to violate this principle, because of some rather complex validation that was necessary. I opted to rely on the DB for the “complete” validation (but made sure my exception text was easily parsed, so a user-friendly error could still be generated). I still had my client-side code do basic input validation, but because of the complexity involved in the complete validation, I did not want to have to maintain two functionally-identical bits of code (one in the client software, one in the DB). I felt that having the same functionality in two places was more likely to lead to future bugs, in case one got updated and the other didn’t. In this case, the server-side validation code was about a 4-page long PL/Perl stored procedure that acted as an INPUT/UPDATE trigger.

    Conclusion: Almost never should you rely on the DB for your user validation. The only exceptions I can think of are the opposite of what you’re asking about: Really complex checks; not the really simple ones.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have defined a function in vim to properly indent folds. Ie so they
Imagine I have a property defined in global.asax. public List<string> Roles { get {
I have a a property defined as: [XmlArray(delete, IsNullable = true)] [XmlArrayItem(contact, typeof(ContactEvent)), XmlArrayItem(sms,
I have defined a personalizable property on a web part and I would like
Basically I have a website. I have a properly setup sitemap so I assume
How can I check whether all JavaScript functions have loaded properly on a page?
i asked this question yesterday but it doesnt seem to have asked properly so
Ok, I am back on this task. I have my XML properly download from
I have the following Wix code,that checks if some registry entry exist it doesn't
So I have columns defined like this: <DataGridTemplateColumn.CellTemplate> <DataTemplate> <TextBox Text={Binding Path=COLUMN_NAME, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.