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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T04:13:11+00:00 2026-06-07T04:13:11+00:00

For years I’ve used mySQL. Big Mistake. PDO is definitely the way to go

  • 0

For years I’ve used mySQL. Big Mistake. PDO is definitely the way to go and I have learnt the hard way.

But I don’t quite understand it yet and am not finding the tutorials particularly helpful.

Security and speed are my too main issues with mySQL. What would a standard PDO formula look like if I wanted to say fetch information from

$variable1 - SQL TABLE
$variable2 - FIELD TO MATCH
$variable3 - MATCH WITH THIS

and then assuming that there are a given number of fields in each found row, once it is found presumably it would look something like $row['field_name'];

If I can see how this is done based on this example I think I can probably manage the rest.

Also if you know a good link for something like what w3schools does for mySQL queries but for PDO then I would appreciate it too.

  • 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-07T04:13:12+00:00Added an answer on June 7, 2026 at 4:13 am

    Fully documented, it looks like this:

    <?php
    
    try {
    //Start connection
        $pdo = new PDO("mysql:host=localhost;dbname=database_name", "user", "password");
    /*
    * Set attributes
    */
    //Throw exceptions on errors
        $pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
    //Disable prepared statements emulations
        $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
    
        $table_name = "example_table";
        $field = "example_field";
        $value = "example_value";
    
        $query = <<<MySQL
        SELECT *
            FROM `$table_name`
            WHERE `$field` = :value
    MySQL;
    
    //Prepare the statement
        $stmt = $pdo->prepare($query);
    
    //Bind values to placeholders
        $stmt->bindValue(":value", $value);
    
    //Execute the statement
        $stmt->execute();
    
    /*
    * Fetching results
    */
    //Fetch all results as an associative array.
        $result = $stmt->fetchAll(PDO::FETCH_ASSOC);
    } catch (PDOException $e) {
        die("An error has occurred! " . $e->getMessage());
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

10 years have ellapsed since I used COM/OLE, and I forget 90% of them.
For years I've been reading about XML and I have just not quite grokked
After years of programming, we all have a set of small functions used as
I have 4+ years of exp in using PHP ! (Zend, CI, CakePHP) but
After years of using the big ugly MFC ASSERT macro, I have finally decided
Years ago I used to have a visual studio plug in (2003 era) which
After years of ASP.NET development I'm actually quite surprised that I can't seem to
For years, on 32-bit systems I have never had a problem. Why can't I
After years in embedded programming, I have to develop a Windows app. I dug
For years I've been coding C++ in the standard way, with class declarations in

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.