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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T07:50:44+00:00 2026-06-18T07:50:44+00:00

I have a large php application (purely php, no frameworks, etc.) which uses an

  • 0

I have a large php application (purely php, no frameworks, etc.) which uses an oracle-db.
All queries are executed like this:

oci_parse($conn_id,"insert into table (bla) values ('bla')");
oci_execute($stmt)

I know this is bad! No need pointing out stuff like “use bind” or something similar. I know that, but I can’t change this.

What we all also know is that you have to escape characters.
This question is especially about the ' charcter.

I have many queries like this:

$query = "INSERT INTO table (field1, field2,field3,field4) VALUES ('bla,bla','blub', 'mimi'm', 'mu's'c'hle')";
$query2 = "UPDATE table SET field1 =  'bla,bla', field2 = 'blub', field3 = 'mimi'm', field4 = 'mu's'c'hle' WHERE field5 = 'lol'zj'd'"

Sure, normally they do not have so many ' in it – but thats just for demonstration.

Now to the question:
Is there any way to validate/escape the whole query-string in php? I can’t think/find of a way to accomplish this, no matter how I think of it.

It’s obvious that it’s easy to escape all values before building the query-strings, by just replacing ' with '' – but is it possible when you only have the whole query as a string (like the examples above)? I personally can’t think of an “universal solution”…

  • 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-18T07:50:45+00:00Added an answer on June 18, 2026 at 7:50 am

    I believe this is insoluble with traditional means, at the time when the query is already built:

    1. Trying to simply add a slash to every apostrophe, of course will not work, because you are escaping the delimiter apostrophes as well as the “in-value” apostrophes.
    2. There is no function or regular expression to determine which are the in-value apostrophes and which are the value-delimiting apostrophes.
    3. Even a parser won’t help you because part of a parser’s job is to tell you when the query has invalid syntax, but not to fix that syntax; as soon as it hits an apostrophe out of place and the following character is not a comma, it will baulk.

    Let’s take part of your second example:

    field3 = 'mimi'm', field4 = 'mu's'c'hle'
    

    A normal query parser would see the field3 value as 'mini' followed by an erroneous m, where it expects a comma. This is not something a parser is designed to handle.

    So suppose we write something custom to handle this. Let’s say we decide that the apostrophe, given that it isn’t followed by a comma, must be part of the value. That’s fine, but what about the next apostrophe, which is intended to be a delimiter?

    How does our code know whether the apostrophe is a delimiter, as opposed to the value actually containing an apostrophe followed by a comma? In fact, the value could contain something that looks exactly like the rest of the query! (Furthermore, how would we detect queries that actually are invalid, once we start to question the structure of the query itself in this way).

    tl;dr

    GIGO = garbage in, garbage out

    You can’t write (traditional) software to sort out an arbitrary mess!

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

Sidebar

Related Questions

I have some very large processing being done in a php application. I'd like
I have a PHP application which runs a large set of SQL files. It
I have a large PHP application. After I changed some settings I get a
I have a very large script which contains a lot of php files, so
I have an existing large(ish) PHP web app (using Apache and MySQL) which now
I have a classifieds website, which uses PHP and MYSQL. I have several pages
I am using CodeCharge Studio to finish a large PHP application. This question isn't
I have a large PHP application and I'm looking for a way to know
I have an application I wrote in PHP (on symfony) that imports large CSV
I built and administer large web application which uses the PHPMailer library to send

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.