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 8812427
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 14, 20262026-06-14T03:36:14+00:00 2026-06-14T03:36:14+00:00

I’ve always relied on my PHP programming for most processes which I need to

  • 0

I’ve always relied on my PHP programming for most processes which I need to do, that I know can be done via a MySQL query or feature. For example:

I know that MySQL has a FOREIGN KEY feature that helps maintain data integrity but I don’t rely on MySQL. I might as well make my scripts do this as it is more flexible; I’m basically using MySQL as STORAGE and my SCRIPTS as the processor.

I would like to keep things that way, put most of the load on my coding. I make sure that my scripts are robust to check for conflicts, orphaned rows, etc every time it makes changes and I even have a SYSTEM CHECK routine that runs through all these data verification processes so I really try to do everything on script side as long as it doesn’t impact the whole thing’s performance significantly (since I know MySQL can do things faster internally I mean I do use MySQL COUNT() functions of course).

Of course any direct changes done to the tables will not trigger routines in my script. but that’s a different story. I’m pretty comfortable with doing this and I plan to keep doing this until I am convinced otherwise.

The only thing that I really have an issue with right now is, checking for duplicates.

My current routine is basically inserting products with serial numbers. I need to make sure that there are no duplicate serial numbers entered into the database.

I can simply rely on MySQL UNIQUE constraint to make sure of this or I can do it script side and this is what I did.

This product routine is a BATCH routine where anything from 1 to 500 products will be entered into the database at one call to the script.

Obviously I check for both duplicate entries in the data submitted as well as the data in the database. Here’s a chunk of my routine

 for ($i = 1; $i <= $qty; $i++) {
    //
    $serial = $serials_array[$i - 1]; // -1 coz arrays start at zero

    //check duplicates in submitted data ++++++++++++++++++++++++++
    if($serial_check[$serial] == 1) { // duplicate found!
            exit("stat=err&statMsg=Duplicate serial found in your entry! ($serial)");
    }else{
        $serial_check[$serial] = 1;
    }


    //check duplicates in database
    if(db_checkRow("inventory_stocks", "WHERE serial='$serial'"))exit("stat=err&statMsg=Serial Number is already used. ($serial)");
    //++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

}

OK so basically it’s:

1) Check submitted data for duplicates via creating an array that I can check against each serial number submitted – THIS IS no problem and really fast with PHP even up to 1000 records.

2) But, to check the database for duplicates, I have to call a function I made (db_checkRow) w/c basically issues a SELECT statement on EACH serial submitted and see if there’s a hit/duplicate.

So, basically, 500 SELECT statements to check for duplicates vs just the MySQL unique constraint feature.

Does it really matter much??

Another reason I design my software like this is because at least if I need to deploy my stuff on a different database I don’t rely too much on database features, hence I can easily port my application with very little tweaking.

  • 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-06-14T03:36:15+00:00Added an answer on June 14, 2026 at 3:36 am

    You’re wrong. You’re very, dangerously wrong.

    The database has been designed for a specific function. You will never beat MySQL at enforcing a unique constraint. The database has been designed to do explicitly that as quickly as possible. It is impossible that you can do it quicker or more efficiently in PHP as you still need to access the database to determine whether the data you’re inserting would be a duplicate.

    This is easily demonstrated by the fact that you have 500 select statements to enforce a single unique constraint. As your table grows this will get even more ridiculous. What happens when your table hits 2,000 rows? What if you have a new table with a million rows?

    Use the database features that have been designed explicitly to make your life easy.

    You’re also assuming that the only way the database will be accessed is through the application. This is an extremely dangerous assumption that is almost certain to be incorrect as time progresses.

    Please read this programmers question, which seems like it’s been written just for you. Simply put, “Never do in code what you can get the SQL server to do well for you”. I cannot emphasise this enough.

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

Sidebar

Related Questions

I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I know there's a lot of other questions out there that deal with this
Does anyone know how can I replace this 2 symbol below from the string
I need a function that will clean a strings' special characters. I do NOT
I'm trying to create an if statement in PHP that prevents a single post
link Im having trouble converting the html entites into html characters, (&# 8217;) i
That's pretty much it. I'm using Nokogiri to scrape a web page what has
I want to count how many characters a certain string has in PHP, but
I am trying to understand how to use SyndicationItem to display feed which is

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.