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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T23:55:17+00:00 2026-05-11T23:55:17+00:00

Can anyone explain what the following PHP Code does function query($query_string) { if ($query_string

  • 0

Can anyone explain what the following PHP Code does


function query($query_string) 
    {
        if ($query_string == "") {
            return 0;
        }

        if (!$this->connect()) {
            return 0; 
        };

        if ($this->QueryID) {
            $this->free_result();
        }

        if ($this->RecordsPerPage && $this->PageNumber) {
            $query_string .= " LIMIT " . (($this->PageNumber - 1) * $this->RecordsPerPage) . ", " . $this->RecordsPerPage;
            $this->RecordsPerPage = 0;
            $this->PageNumber = 0;
        } else if ($this->RecordsPerPage) {
            $query_string .= " LIMIT " . $this->Offset . ", " . $this->RecordsPerPage;
            $this->Offset = 0;
            $this->RecordsPerPage = 0;
        }

        $this->QueryID = @mysql_query($query_string, $this->LinkID);
        $this->Row   = 0;
        $this->Errno = mysql_errno();
        $this->Error = mysql_error();
        if (!$this->QueryID) {
            $this->halt("Invalid SQL: " . $query_string);
        }

        return $this->QueryID;
    }

function next_record() 
    {
        if (!$this->QueryID) {
            $this->halt("next_record called with no query pending.");
            return 0;
        }

        $this->Record = @mysql_fetch_array($this->QueryID);
        $this->Row   += 1;
        $this->Errno  = mysql_errno();
        $this->Error  = mysql_error();

        $stat = is_array($this->Record);
        if (!$stat && $this->AutoFree) {
            $this->free_result();
        }
        return $stat;
    }

Can the above be done in a simpler way , would it be wise to use an ORM ?

  • 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-11T23:55:18+00:00Added an answer on May 11, 2026 at 11:55 pm

    The first class method looks like it performs a MySQL query and adds a LIMIT clause for pagination. The second moves the current query onto the next record, while incrementing the pagination counters.

    In more detail, here’s the first sample:

    • Exit the method if the query is empty or the database connection doesn’t exist.
    • Free any existing query.
    • If the number of records per page and page number are set:
      • Add them to the LIMIT clause of the query.
      • And reset them to 0.
    • Otherwise if records per page is set:
      • Add it to the LIMIT clause of the query.
      • And reset them to 0.
    • Run the query.
    • Set the current row to 0.
    • Collect errors.
    • If the query failed halt with the error.
    • Return the query.

    And the second:

    • If the query is not set halt with an error.
    • Fetch row information as an array for the current row.
    • Increment the row number.
    • Catch any errors.
    • If the result isn’t an array free/close the query.
    • Otherwise return the result set.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 201k
  • Answers 201k
  • 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
  • Editorial Team
    Editorial Team added an answer It depends on the font format. Some fonts are bitmapped,… May 12, 2026 at 8:10 pm
  • Editorial Team
    Editorial Team added an answer Unlike PHP, you normally use JSP for presentation only. Despite… May 12, 2026 at 8:10 pm
  • Editorial Team
    Editorial Team added an answer in its default setting SQL*Plus won't deal properly with blank… May 12, 2026 at 8:10 pm

Related Questions

I am debugging a php application. In the Local Debugging window, it shows the
I'm in the process of trying to move our company from SalesForce to SugarCRM,
Can anyone please explain what the following code checks for? I can make no
Can anyone explain to me what the following line of C# code does? public

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.