Jump to content

is it efficient ?


Nikandlv
Go to solution Solved by Jacques1,

Recommended Posts

Hi , 

Im wondering if is it efficient to do a sql (using pdo) quary for every visitor of website ?

for example 

we have a page 

and we have a  <h1> tag  and its how we use it in here 

<?php

echo '<h1>';

echo getthewebsitetitlefromdbfunctionlol() ;

echo '</h1>;

?>

and the getthewebsitetitlefromdbfunctionlol() will basically selects the title from db and return it .

so is it efficient to do this for every visitor of the page ? 

Link to comment
Share on other sites

Well, I suppose it is more efficient to hardcode the title, but it is less flexible and realistically, it the performance doesn't matter.

 

But instead, why not get all your site information with one query, and then just echo("<h1>$siteStuff[title]</h1>");?

i guess so ,  that will be a good idea to get the info as an array for all of stuff i want in my page i t will do the request once 

thanks for the suggestion 

Link to comment
Share on other sites

This discussion is silly. Every nontrivial web application makes dozens or hundreds of queries per request, and modern database systems can easily handle this. That's what they're made for. Even complex queries involving millions of rows (not just some title lookup) are no problem at all as long as you use proper indexes. Query results are also cached, so the query isn't actually executed “for every visitor”.

 

Stop trying to solve problems that aren't there.

Link to comment
Share on other sites

This discussion is silly. Every nontrivial web application makes dozens or hundreds of queries per request, and modern database systems can easily handle this. That's what they're made for. Even complex queries involving millions of rows (not just some title lookup) are no problem at all as long as you use proper indexes. Query results are also cached, so the query isn't actually executed “for every visitor”.

 

Stop trying to solve problems that aren't there.

then sorry for asking ! i was wondering how it works .

im not that level experienced to know that 

Link to comment
Share on other sites

  • Solution

No need to apologize. I'm simply pointing out that efficiency isn't the issue here.

 

Choose the most readable solution. If it makes sense to only fetch the title, that's perfectly valid. It doesn't matter if you need a few extra queries, because there won't be any performance difference at all.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.