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

  • Home
  • SEARCH
  • 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 106971
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T01:40:50+00:00 2026-05-11T01:40:50+00:00

I am trying to create a column in a table that’s a foreign key,

  • 0

I am trying to create a column in a table that’s a foreign key, but in MySQL that’s more difficult than it should be. It would require me to go back and make certain changes to an already-in-use table. So I wonder, how necessary is it for MySQL to be sure that a certain value is appropriate? Couldn’t I just do that with a language like PHP, which I’m using to access this database anyway?

Similarly with NOT NULL. If I only access this database with PHP, couldn’t I simply have PHP ensure that no null value is entered?

Why should I use MySQL to do enforce these constraints, when I could just do it with PHP?


I realize that NOT NULL is a very stupid part to neglect for the above reasons. But MySQL doesn’t enforce foreign keys without a serious degree of monkeying around.

In your opinion, would it still be bad to use the ‘fake’ foreign keys, and simply check if the values to be entered are matched in other tables, with PHP?

  • 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. 2026-05-11T01:40:51+00:00Added an answer on May 11, 2026 at 1:40 am

    You are going to make mistakes with PHP, 100% guaranteed. PHP is procedural. What you want are declarative constraints. You want to tell the entire stack: ‘These are the constraints on the data, and these constraints cannot be violated.’ You don’t want to much around with ‘Step 1 … Step 2 … Step 3 … Step 432 …’, as your method of enforcing constraints on data, because

    • you’re going to get it wrong
    • when you change it later, you will forget what you did now
    • nobody else will know all of these implicit constraints like you know them now, and that includes your future self
    • it takes a lot of code to enforce constraints properly and all the time – the database server has this code already, but are you prepared to write it?

    The question should actually be worded, ‘Why should I use PHP to enforce these constraints, when I could just do it with MySQL?’

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

Sidebar

Ask A Question

Stats

  • Questions 89k
  • Answers 89k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer Add a handler for the wx.EVT_ICONIZE event. May 11, 2026 at 5:53 pm
  • Editorial Team
    Editorial Team added an answer This should give you a list (provided you allow people… May 11, 2026 at 5:53 pm
  • Editorial Team
    Editorial Team added an answer Use map instead of each to simplify your code: $('.MyClass').map(… May 11, 2026 at 5:53 pm

Related Questions

I am trying to create a column in a table that's a foreign key,
I am trying to create an XML file based on data fields from a
I am trying to figure out if it is possible to create a foreign
I'm trying to optimize a stored procedure I'm maintaining, and am wondering if anyone
In my specific case, I am making use of a discriminator column strategy. This

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.