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

  • Home
  • SEARCH
  • 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 8050281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 5, 20262026-06-05T07:01:49+00:00 2026-06-05T07:01:49+00:00

How do you fetch one single record from a MySQL database using a PDO

  • 0

How do you fetch one single record from a MySQL database using a PDO prepared statement?

In the “old” way of doing it, I could use:

$MyCaption = mysql_result(mysql_query("SELECT * FROM `photos` WHERE `id` = '56465843362'"),0,"caption");

What would be the PDO prepared statement equivalent?

I tried:

$id = '56465843362';
$query = $db->prepare("SELECT `caption` FROM `photos` WHERE `id` = ?");
$query->execute(array($id));
$caption = $query->fetchColumn();

… but that was wrong.

  • 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-05T07:01:53+00:00Added an answer on June 5, 2026 at 7:01 am
    SELECT `caption` FROM `photos` WHERE `id` = ? Limit 1
    

    The Limit keyword limits to the # of rows you want. But without an order by clause, your record would be randomly fetched. If it seems to be working correctly, do not assume it would behave so always. The SQL standard does not guarantee the order of the rows fetched by default.

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

Sidebar

Related Questions

What's the best way to print from MySQL using PHP when you know there's
I have one table TABLE_QUESTION. I need to fetch record by passing exam_id and
My application often fetch data from a webpage using WebRequest, but it isn't possible
I have the folowing code to fetch a record and update one column which
I am using google's appengine api from google.appengine.api import urlfetch to fetch a webpage.
I have a MySQL database table containing information about places. I'm trying to fetch
I'd like to use a single SQL query (in MySQL) to find the record
How can I fetch more than 1000 record from data store and put all
I have different queries fetching from different tables in one single page. i want
I have one million URL list to fetch. I use this list as nutch

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.