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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T05:07:31+00:00 2026-06-15T05:07:31+00:00

I’m attempting to write a stored procedure in MySql that will take a single

  • 0

I’m attempting to write a stored procedure in MySql that will take a single parameter, and then check that parameter for any text that contains ‘DROP’,’INSERT’,’UPDATE’,’TRUNCATE’, etc., pretty much anything that isn’t a SELECT statement. I know it’s not ideal, but, unfortunately the SELECT statement is being built client-side, and to prevent some kind of man-in-the-middle change, it’s just an added level of security from the server.

I’ve tried doing several means of accomplishing it, but, it’s not working for me. I’ve come up with things similar to this:

CREATE PROCEDURE `myDatabase`.`execQuery` (in INC_query text)
BEGIN

#check to see if the incoming SQL query contains INSERT, DROP, TRUNCATE, 
#or UPDATE as an added measure of security
IF (
    SELECT LOCATE(LOWER(INC_query),'drop') OR
    SELECT LOCATE(LOWER(INC_query),'truncate') OR
    SELECT LOCATE(LOWER(INC_query),'insert') OR
    SELECT LOCATE(LOWER(INC_query),'update') OR
    SELECT LOCATE(LOWER(INC_query),'set')
    >= 1) 
THEN
    SET @command = INC_query;
    PREPARE statement FROM @command;
    EXECUTE statement;
ELSE
    SELECT * FROM database.otherTable; #just a generic output to know the procedure executed correctly, and will be removed later. Purely testing.

END IF;

END

Even if it contains any of my “filterable” words, it still executes the query. Any help would be appreciated, or if there’s a better way of doing something, I’m all ears.

  • 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-15T05:07:33+00:00Added an answer on June 15, 2026 at 5:07 am

    What if you have a column called updated_at or settings? You can’t possibly expect this to work as you intend. This kind of technique is the reason there’s so many references to clbuttic on the web.

    You’re really going to make a mess of things if you go down this road.

    The only reasonable way to approach this is to send in the parameters for the kind of query you want to construct, then construct the query in your application using a vetted white list of allowed terms. An example expressed in JSON:

    {
        "select" : {
          "table" : "users",
          "columns" : [ "id", "name", "DROP TABLE users", "SUM(date)", "password_hash" ],
          "joins" : {
             "orders" : [ "users.id", "orders.user_id" ]
          }
    }
    

    You just need to create a query constructor that emits this kind of thing, and another that converts it back into a valid query. You might want to list only particular columns for querying, as certain columns might be secret or internal only, not to be disclosed, like password_hash in this example.

    You could also allow for patterns like (SUM|MIN|MAX|AVG)\((\w+)\) to capture specific grouping operations or JOIN conditions. It depends on how far you want to take this.

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

Sidebar

Related Questions

I'm parsing an RSS feed that has an ’ in it. SimpleXML turns this
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
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
I'm working with an upstream system that sometimes sends me text destined for HTML/XML
I have a bunch of posts stored in text files formatted in yaml/textile (from
I have a string like this: La Torre Eiffel paragonata all’Everest What PHP function
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
For some reason, after submitting a string like this Jack’s Spindle from a text

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.