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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:48:23+00:00 2026-05-24T09:48:23+00:00

I have been creating a php application that makes quite a few queries to

  • 0

I have been creating a php application that makes quite a few queries to the database i’d say roughly around 30 or so each page load. This is needed due to the nature of the application. I am using OOP php techniques and optimising my queries as much as I can. Should I be using some sort of caching system? or would you say 30 is fine? Here is a typical query.

Ok so my __construct looks like this:

public function __construct($host = 'localhost', $user = 'root', $pass = 'root', $name = 'advert') 
    {   
        $this->_conn = new mysqli($host, $user, $pass, $name)
            or trigger_error('Unable to connect to the server, please check your credentials.', E_USER_ERROR);
    }

And one method like so.

$sql = "SELECT `advert_id`,
                        `ad_title`,
                        `ad_image` FROM adverts WHERE UNIX_TIMESTAMP() < `ad_expires` AND `ad_show` = 0 AND `ad_enabled` = 1 ORDER BY `ad_id` DESC LIMIT 1";

        $stmt = $this->_conn->prepare($sql);
        if ($stmt) {
            $stmt->execute();
            $stmt->bind_result($ad_id, $ad_title, $ad_image);
            $rows = array();
            while ($row = $stmt->fetch()) {
                $item = array(
                    'ad_id' => $ad_id,
                    'ad_title' => $ad_title,
                    'ad_image' => $ad_image
                );
                $rows[] = $item;
            }

The app is kinda like this throughout.

Thanks any feedback will be much appreciated.

**EDIT Sorry i meant to say 30 queries not 30 connections

  • 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-24T09:48:24+00:00Added an answer on May 24, 2026 at 9:48 am

    Just make one connection and re-use it. 30 connections is a lot considering that you might have multiple users.

    Edit: initial question said connections. 30 queries is fine unless this is data that doesn’t change very often. In this case you can first do a query to see if you need to pull data or if the cached data is fine to serve to the user.

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

Sidebar

Related Questions

I have been working on creating an application that sends a string from an
I have been creating Unit tests like crazy and find that I'm often having
I have been tasked with creating a program that will generate an amortization schedule.
I have been creating a helper class for the Facebook PHP API in order
Im a newbie PHP programmer and I have a few questions about creating a
I've been creating this pretty large web application for sometime and have been updating
I have been toying around with creating soap servers in Delphi then running and
I have been working on creating a PHP email form recently and cannot manage
I have been creating a website with Ruby on Rails, and will be hosting
I have been tasked with creating a program what will create take files 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.