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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 21, 20262026-05-21T17:29:59+00:00 2026-05-21T17:29:59+00:00

I am switching to PDO from traditional mysql_query() parameterized queries to make use of

  • 0

I am switching to PDO from traditional mysql_query() parameterized queries to make use of it’s security advantages and I have a few questions. First off, does anything need to be done as far as magic_quotes? This web app will be installed on systems of different configurations and some will (unfortunately) have them on while others will be off. Previously I was doing the whole if statement to addslashes() when it’s off to input data… what needs to be done with PDO queries like these:

$dbh = new PDO("mysql:host=$db_server;dbname=$db_database", $db_username, $db_password);
$sth = $dbh->prepare("SELECT * FROM `users` WHERE `username` = :username ");
$sth->bindParam(':username', $_POST['username']);
$sth->execute();
if($row = $sth->fetch()){
    // Yup
}
$dbh = null;

Also, how necessary is it to close the database handler in the end? What is the detriment of not doing so? Is PDO a good option for a CMS that will be installed on many different server setups? Is PDO ubiquitous enough where it will be enabled on most servers?

Thanks in advance!

  • 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-21T17:29:59+00:00Added an answer on May 21, 2026 at 5:29 pm

    This web app will be installed on systems of different configurations and some will (unfortunately) have [magic quotes] on while others will be off.

    As I noted in a comment on another answer, the PHP manual has an entire section on dealing with dealing with the horror that is magic quotes. You can usually either disable it locally in an .htaccess or correct the data as it comes in. I personally would not do business with a hosting provider that has it enabled by default.

    Previously I was doing the whole if statement to addslashes() when it’s off to input data

    Yikes! addslashes is not adequate protection. When using the old MySQL extension, you need to use mysql_real_escape_string after setting the character set. Failing to do this can leave you open to a huge vulnerability.

    … what needs to be done with PDO queries like these:

    Other than setting the connection character set, nothing! PDO will use real prepared statements when it can. This means that it will first send the query with placeholders to the server so it can process it, then it will later separately send the arguments over. This makes the query immune from SQL injection.

    (Some databases don’t support prepared statements with PDO. For these, PDO will process the query, replacing the placeholders with quoted, escaped values. The result is the same — immunity from SQL injection.)

    Also, how necessary is it to close the database handler in the end? What is the detriment of not doing so?

    Just like the other PHP database handlers, there is no need to close the connection — when the script ends, the connection will close. (Don’t even think about persistent connections.)

    Is PDO a good option for a CMS that will be installed on many different server setups? Is PDO ubiquitous enough where it will be enabled on most servers?

    PDO became standard in PHP 5.1, but that doesn’t mean it’s always available. Most Linux distributions split out all of PHP’s database access options so that installing them also installs the mandatory libraries. Sometimes, incompetent or inexperienced hosting providers won’t install the PDO packages to go along with the other database access options, not realizing what they are doing. This is usually corrected by simply asking them to enable PDO, and switching to another host if they are unwilling or unable.

    Many modern frameworks prefer building on top of PDO, but make other options available. For example, Zend Framework’s Zend_Db has adapters for PDO, mysqli, and a few others. If you fear PDO won’t always be available, using an adapter layer might work well for you. (Like most ZF components, Zend_Db doesn’t rely heavily on other ZF components, meaning you can easily bundle it with your code.)

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

Sidebar

Related Questions

I am switching from plain mysql in php to PDO and I have noticed
Ever since switching from TABLE-layout to DIV-layout, one common problem remains: PROBLEM : you
We are considering switching from MS Visual Studio 2003 to MS Visual Studio 2005
I am switching to textmate and there are a few things I want to
We're considering switching our site from Prototype to jQuery. Being all-too-familiar with Prototype, I'm
To make things easier when switching between machines (my workstation at the office and
My group is thinking about switching our platform for web UI from ASP.net to
I am using the PDO Database Abstraction library to make sure my code is
As you may have known that I switched from ubuntu to windows from my
Switching to GCC for the first time, and I'm getting a bit confused by

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.