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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T04:29:08+00:00 2026-06-16T04:29:08+00:00

I have a website with lots of PHP files (really a lot…), which use

  • 0

I have a website with lots of PHP files (really a lot…), which use the pg_query and pg_exec functions which do not
escape the apostrophe in Postgre SQL queries.

However, for security reasons and the ability to store names with
apostrophe in my database I want to add an escaping mechanism for my database input. A possible solution is to go
through every PHP file and change the pg_query and pg_exec to use pg_query_params but it is both time consuming
and error prone. A good idea would be to somehow override the pg_query and pg_exec to wrapper functions that would
do the escaping without having to change any PHP file but in this case I guess I will have to change PHP function
definitions and recompile it which is not very ideal.

So, the question is open and any ideas that would
allow to do what I want with minimum time consumption are very welcome.

  • 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-16T04:29:09+00:00Added an answer on June 16, 2026 at 4:29 am

    This is a perfect example of when a database layer and associated API will save you loads of time. A good solution would be to make a DB class as a singleton, which you can instantiate from anywhere in your app. A simple set of wrapper functions will allow you to make all queries to the DB go through one point, so you can then alter the way they work very easily. You can also change from one DB to another, or from one DB vendor to another without touching the rest of the app.

    The problem you are having with escaping is properly solved by using the PDO interface, instead of functions like pg_query(), which makes escaping unnecessary. Seeing as you’ll have to alter everywhere in your app that uses the DB, you may as well refactor to use this pattern at the same time as it’ll be the same amount of work.

    class db_wrapper {
    
        // Singleton stuff
        private $instance;
    
        private function __construct() {
            // Connect to DB and store connection somewhere
        }
    
        public static function get_db() {
            if (isset($instance)) {
                return $instance;
            }
            return $instance = new db_wrapper();
        }
    
        // Public API
    
        public function query($sql, array $vars) {
            // Use PDO to connect to database and execute query
        }
    
    }
    
    // Other parts of your app look like this:
    
    function do_something() {
        $db = db_wrapper::get_db();
        $sql = "SELECT * FROM table1 WHERE column = :name";
        $params = array('name' => 'valuename');
        $result = $db->query($sql, $params);
    
        // Use $result for something. 
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a website which uses jQuery and lots of mouseover / mouseout effects.
I received a demand to correct a ASP website that have lots of functions
I have website on the server, which is not precompiled (with source code, so
I am learning php and have a book which has lots of examples and
I have recreated a website and have lots of 301 to handle (from php
i have website of application which sells applications online.on the home page i want
So, I've created a website and I have lots of pages in the public_html
I am creating a website and the design have lots of background images so
I'm creating a movies website, IMDB.com like.. I'm really new to PHP and programming
I have a PHP variable thePHPvar in a file DoStuff.php in my website. thePHPvar

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.