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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 10, 20262026-05-10T22:06:27+00:00 2026-05-10T22:06:27+00:00

Generally I connect and retrieve data using the standard way (error checking removed for

  • 0

Generally I connect and retrieve data using the standard way (error checking removed for simplicity):

$db = mysql_select_db('dbname', mysql_connect('host','username','passord')); $items = mysql_query('SELECT * FROM $db');  while($item = mysql_fetch_array($items)) {     my_function($item[rowname]); } 

Where my_function does some useful things witht that particular row.

What is the equivalent code using objects?

  • 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. 2026-05-10T22:06:28+00:00Added an answer on May 10, 2026 at 10:06 pm

    Since version 5.1, PHP is shipped with the PDO driver, which gives a class for prepared statements.

    $dbh = new PDO("mysql:host=$hostname;dbname=$db", $username, $password); //connect to the database //each :keyword represents a parameter or value to be bound later $query= $dbh->prepare('SELECT * FROM users WHERE id = :id AND password = :pass');  # Variables are set here. $query->bindParam(':id', $id); // this is a pass by reference  $query->bindValue(':pass', $pass); // this is a pass by value   $query->execute(); // query is run   // to get all the data at once $res = $query->fetchall(); print_r($res); 

    see PDO driver at php.net

    Note that this way (with prepared statements) will automatically escape all that needs to be and is one of the safest ways to execute mysql queries, as long as you use binbParam or bindValue.

    There is also the mysqli extension to do a similar task, but I personally find PDO to be cleaner.

    What going this whole way around and using all these steps gives you is possibly a better solution than anything else when it comes to PHP.

    You can then use $query->fetchobject to retrieve your data as an object.

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

Sidebar

Ask A Question

Stats

  • Questions 70k
  • Answers 70k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • added an answer I got ODBC trace with those settings in my odbc.ini:… May 11, 2026 at 12:56 pm
  • added an answer Is there any particular reason why you can't include your… May 11, 2026 at 12:56 pm
  • added an answer I wish I could offer you more in terms of… May 11, 2026 at 12:56 pm

Related Questions

Generally when I use ClickOnce when I build a VB.NET program but it has
I generally use a manual process: Look at the page, figure out the semantic
I generally stay away from regular expressions because I seldom find a good use
I generally try and keep all related entities in the same repository. The following
Maybe you can help me... I am writing a program in Windows Mobile that
I've got an unusual situation: I'm using a Linux system in an embedded situation
I am working on a new licensing system for our companies software. We are
I don't know how authoritative this is but I found this: http://www.sqlite.org/cvstrac/wiki?p=PerformanceConsiderations and it

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.