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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T22:14:40+00:00 2026-05-25T22:14:40+00:00

So, if I want to pull some data from my database (PHP, MySql), whether

  • 0

So, if I want to pull some data from my database (PHP, MySql), whether I’m writing for a class or hard-coded, I’ve been doing something along the lines of:

$x = "SELECT <column(s)> FROM <table> WHERE <conditions>";
$y = mysql_query($x);
while($result = mysql_fetch_assoc($y))
{
echo $result['column']; // etc
}

Obviously I use a function or class (depending on design pattern) so pulling data like this is done in one line, I just wondered if I was doing ‘too much work’ and if there was a quicker way of doing this.

Thanks.

  • 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-25T22:14:41+00:00Added an answer on May 25, 2026 at 10:14 pm

    You can get tighter code by using a more up-to-date PHP module to access your database.

    The mysql_xxx() functions that you’re using have been superseded by the mysqli_xxx() functions. This uses similar code, but provide more features and security than the older library:

    $query = 'SELECT <column(s)> FROM <table> WHERE <conditions>';
    if ($result = $mysqli->query($query)) {
        while ($row = $result->fetch_assoc()) {
            print $row['column'];
        }
    }
    

    You can find out more about MySQLi (including how it differs from the old MySQL library) here: http://php.net/manual/en/book.mysqli.php

    But for really concise code, you might consider looking into the PDO library. Your query could be expressed with PDO like this:

    $sql = 'SELECT <column(s)> FROM <table> WHERE <conditions>';
    foreach ($conn->query($sql) as $row) {
        print $row['column'];
    }
    

    …and if you really wanted to, the first two lines of that code could be combined as well.

    Find out more about PDO at the PHP manual site: http://www.php.net/manual/en/book.pdo.php

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

Sidebar

Related Questions

I have data that I want to pull from a mySQL database and I
I want to pull out duplicate records in a MySQL Database. This can be
I have a multidocument application. I want to pull data from each of those
I have to pull some data from an ERP system (SAP) in C#. Without
I want to pull data from table Province_Notifiers and also fetch all corresponding items
Possible Duplicate: PHP Curl script to pull data from remote server every 10 minutes
I'm working with some data which is being retrieved from my database. It's placed
I've got a situation which I want to fetch data from a database, and
I have a remote monotone repos I want to pull from, but I really
I've forked a Mercurial repository, and now I want to pull the changes from

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.