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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T07:36:00+00:00 2026-05-23T07:36:00+00:00

I was just wondering if there was a way I could use some form

  • 0

I was just wondering if there was a way I could use some form of prepared statements in MySQL so I wouldn’t have to escape all my inputs and I wouldn’t have to switch all of my files from MySQL to MySQLi. I really don’t trust the escaping functions, so if there is any alternatives that work in regular MySQL, it would be great.

  • 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-05-23T07:36:00+00:00Added an answer on May 23, 2026 at 7:36 am

    Use PDO (PHP Data Objects) to connect to your MySQL database. This method will make sure that all database input will always be treated as text strings and you will never have to do any manual escaping.

    This combined with proper use of html_entities() to display data from your database is a solid and good way to protect your page from injection. I always use PDO to handle all my database connections in my projects.

    Create database object (and in this case enforce a certain character encoding):

    try {
        $db = new PDO("mysql:host=[hostname];dbname=[database]",'[username]','[password]');
        $db->setAttribute(PDO::MYSQL_ATTR_INIT_COMMAND, "SET NAMES utf8");
        $db->setAttribute(PDO::ATTR_ERRMODE,PDO::ERRMODE_EXCEPTION);
        $db->exec('SET NAMES utf8');
    } catch (PDOException $e) {
        echo $e->getMessage();
    }
    

    Then use it like so:

    $id = 1;
    $q = $db->prepare('SELECT * FROM Table WHERE id = ?');
    $q->execute(array($id));
    $row = $q->fetch();
    echo $row['Column_1'];
    

    or

    $q = $db->prepare('UPDATE Table SET Column_1 = ?, Column_2 = ? WHERE id = ?');
    $q->execute(array('Value for Column_1','Value for Column_2',$id));
    

    and with wildcards:

    $search = 'John';
    $q = $db->prepare('SELECT * FROM Table WHERE Column_1 LIKE ?');
    $q->execute(array('%'.$search.'%'));
    $num = $q->rowCount();
    if ($num > 0) {
      while ($row = $q->fetch()) {
        echo $row['Column_1'];
      }
    } else {
      echo "No hits!";
    }
    

    Read more:

    How can I prevent SQL injection in PHP?

    When *not* to use prepared statements?

    how safe are PDO prepared statements

    http://php.net/manual/en/book.pdo.php

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

Sidebar

Related Questions

I was just wondering if there was some way I could actually rename the
Just wondering if there is a way in Spring to have a parent controller:
Just wondering is there any way I can check whether the url links to
just wondering if there is a way to reduce the amount of code needed
Just wondering if there is any way to get the NS records in C#.
I'm just wondering if there is a way to set a vertical threshold of
Cascading deletes aren't setup on this particular database. Just wondering if there's a way
just was wondering if there is a way to access a method from my
I'm just wondering, is there any way to run Selenium tests on Android in
I was wondering if there is a way to print just the structure of

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.