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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T23:24:16+00:00 2026-06-17T23:24:16+00:00

Possible Duplicate: How prepared statements can protect from SQL injection attacks? For those of

  • 0

Possible Duplicate:
How prepared statements can protect from SQL injection attacks?

For those of us that are new to PDO, we get that it is more secure and that it is better to use, but what I can’t wrap my brain around is, how is this secured?

<?php
$db = new PDO('mysql:host=localhost;dbname=testdb;charset=UTF-8', 'username', 'password');
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
try {
    //connect as appropriate as above
    $db->query('hi'); //invalid query!
} catch(PDOException $ex) {
    echo "An Error occured!"; //user friendly message
    some_logging_function($ex->getMessage());
}
foreach($db->query('SELECT * FROM table') as $row) {
    echo $row['field1'].' '.$row['field2']; //etc...
}
?>

Mind you, I do understand what it does, but what exactly does it do to sanitize input? I know mysql_* use mysql_real_escape_string which just put the literal \. Does PDO use this same system? If not, what are we relying on as far as sanitation?

  • 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-17T23:24:17+00:00Added an answer on June 17, 2026 at 11:24 pm

    While there doesn’t seem to be anything to sanitize as input in your query. Furthermore, if you just put in your query it will not do anything to it.

    But it does have the magic called prepared statements, which does help you. You can check @yourcommonsense ‘s link for more information on that:

    How can prepared statements protect from SQL injection attacks?

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

Sidebar

Related Questions

Possible Duplicate: How prepared statements can protect from SQL injection attacks? If I'm using
Possible Duplicate: How to prevent SQL injection in PHP? I use PDO prepared statements
Possible Duplicate: Retrieve (or simulate) full query from PDO prepared statement I can't figure
Possible Duplicate: java PreparedStatement Can I make the prepared statement SELECT * FROM STUDENTS
Possible Duplicate: How can I prevent SQL injection in PHP? This is the example
Possible Duplicate: How can I get the SQL of a PreparedStatement? I make a
Possible Duplicate: MySQL / PDO / Prepared Statements - All a big jump, a
Possible Duplicate: Can PHP PDO Statements accept the table name as parameter? Im writing
Possible Duplicate: how safe are PDO prepared statements So I was looking into PDO
Possible Duplicate: PDO Prepared Statements I'm using the mysqli extension in PHP and I'm

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.