Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Are static pages "easier" on a webserver then getting content from a database?
Old 03-21-2011, 07:23 PM Are static pages "easier" on a webserver then getting content from a database?
Super Talker

Posts: 113
Trades: 0
If I have a few dozen webpages that have, say, 5000 characters in them, is it "easier" (sorry I don't know a more technical term ) for the webserver to pull the content from a table in a mySQL database and then "echo" it out on the page, or to have a static html page? Is there a significant difference? I would kind of like to store my content in columns in tables in a mySQL database because I can manipulate the data before outputting it to the page, but I don't want to bog down my server.

Thanks for your advice!
Learnin' n00b is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-21-2011, 07:53 PM Re: Are static pages "easier" on a webserver then getting content from a database?
benicio's Avatar
Ultra Talker

Posts: 472
Trades: 0
static page would be easier of course
__________________

Please login or register to view this content. Registration is FREE
|
Submit Your Articles in a
Please login or register to view this content. Registration is FREE


Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Please login or register to view this content. Registration is FREE
benicio is offline
Reply With Quote
View Public Profile Visit benicio's homepage!
 
Old 03-21-2011, 07:59 PM Re: Are static pages "easier" on a webserver then getting content from a database?
Super Talker

Posts: 113
Trades: 0
Is there a significant difference, though? I mean, will I be putting a lot more stress on the server by storing the pages in a database?
Learnin' n00b is offline
Reply With Quote
View Public Profile
 
Old 03-21-2011, 08:50 PM Re: Are static pages "easier" on a webserver then getting content from a database?
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Yes, reading in data from a database puts more 'stress' on the server. The amount of stress depends on a lot of factors, including how well you implement your script and design your database. Clearly though, the amount of stress isn't prohibitive considering that the vast majority of sites you visit are using some form of database to store content. Every post in this forum, for example, is stored in a database (over 1 million of them total according to the stats in the footer).
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 03-22-2011, 10:10 AM Re: Are static pages "easier" on a webserver then getting content from a database?
Super Talker

Posts: 113
Trades: 0
So, if I'm making a query and I just need one column from a row in a table, would it be a lot better to use a query like this:

Code:
'SELECT age from fruittable WHERE fruit = orange' // this reads one cell?
as opposed to this

Code:
'SELECT * from fruittable WHERE fruit = orange' // this reads the whole row?
Learnin' n00b is offline
Reply With Quote
View Public Profile
 
Old 03-22-2011, 12:21 PM Re: Are static pages "easier" on a webserver then getting content from a database?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
If the database server is ON THE SAME machine it may take marginally more resources to produce the page.

BUT by NOT using inefficient "SELECT * FROM" the difference will be negligible unless the hardware is grossly underpowered.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 03-22-2011, 12:30 PM Re: Are static pages "easier" on a webserver then getting content from a database?
Super Talker

Posts: 113
Trades: 0
I think the database is on a different server.

Quote:
BUT by NOT using inefficient "SELECT * FROM" the difference will be negligible unless the hardware is grossly underpowered.
So what should I use in place of the "SELECT * FROM" statement?
Learnin' n00b is offline
Reply With Quote
View Public Profile
 
Old 03-22-2011, 12:31 PM Re: Are static pages "easier" on a webserver then getting content from a database?
bas
Super Talker

Posts: 108
Name: Bas
Trades: 0
In general it is a good practice to always make a query do as much as possible, to keep the amount of transmitted data small. Moreover, using the `*'-symbol hides the implementation of the table, so its behaviour may change when you ever decide to change the structure of the database. This may be bad for code visibility.
bas is offline
Reply With Quote
View Public Profile
 
Old 03-22-2011, 12:36 PM Re: Are static pages "easier" on a webserver then getting content from a database?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
So what should I use in place of the "SELECT * FROM" statement?
A comma seperated list of the columns you need to return in the recordset, using * forces two passes of the tables, one to read the column names and their index number, with the second pass to retrieve the data from the rows.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 03-22-2011, 01:48 PM Re: Are static pages "easier" on a webserver then getting content from a database?
Super Talker

Posts: 113
Trades: 0
Quote:
A comma seperated list of the columns you need to return in the recordset, using * forces two passes of the tables, one to read the column names and their index number, with the second pass to retrieve the data from the rows.
So even if I'm selecting all of the columns in the row, I should use the comma separated list in the query?

Say I have the following table named "fruittable":
Code:
 index         fruit               age            origin
int(10)      varchar(50)        varchar(50)     varchar(50)
Just to make sure I understand, to get one field, say "age", from the row where the "fruit" equals "orange" (only one column out of the row) I use:
Code:
$query='SELECT age from fruittable WHERE fruit = orange';
To get all the cells (all the columns in the row), I use:
Code:
$query='SELECT fruit, age, origin from fruittable WHERE fruit = orange';
Then in either case, to get the actual values do I go:
Code:
$result = mysql_query($query);
$row = mysql_fetch_array($result, MYSQL_NUM);
Then the value(s) would be in the array which I could then access?

Thanks for helping me understand
Learnin' n00b is offline
Reply With Quote
View Public Profile
 
Old 03-22-2011, 02:09 PM Re: Are static pages "easier" on a webserver then getting content from a database?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Quote:
I should use the comma separated list in the query?
Yes


Quote:
Just to make sure I understand, to get one field, say "age", from the row where the "fruit" equals "orange" (only one column out of the row) I use:


PHP Code:
$query='SELECT age from fruittable WHERE fruit = orange'
Yes

Quote:
To get all the cells (all the columns in the row), I use:
PHP Code:
$query='SELECT fruit, age, origin from fruittable WHERE fruit = orange'
Yes

Quote:
Then in either case, to get the actual values do I go:

PHP Code:
$result mysql_query($query);
$row mysql_fetch_array($resultMYSQL_NUM); 
Then the value(s) would be in the array which I could then access?
By using MYSQL_NUM as the array type you would access the results using ONLY the index numbers, eg: $row[colNo] where the index numbers are in the order that you specified the column names in the query (zero based).

Using "SELECT *" returns them in the order they are in the table, so if your later code then uses $row[n] and the table has been restructured for some reason, the output from your code will be in error, and in the best case it will crash, with the worst case scenario of giving erroneous calculations that are not detected.
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 03-22-2011, 04:02 PM Re: Are static pages "easier" on a webserver then getting content from a database?
Super Talker

Posts: 113
Trades: 0
Thanks for explaining that! It makes sense now
Learnin' n00b is offline
Reply With Quote
View Public Profile
 
Old 04-03-2011, 10:48 PM Re: Are static pages "easier" on a webserver then getting content from a database?
Super Talker

Posts: 113
Trades: 0
Quote:
By using MYSQL_NUM as the array type you would access the results using ONLY the index numbers, eg: $row[colNo] where the index numbers are in the order that you specified the column names in the query (zero based).
Is MYSQL_NUM more efficient than MYSQL_ASSOC, or is there no difference?

Quote:
Using "SELECT *" returns them in the order they are in the table, so if your later code then uses $row[n] and the table has been restructured for some reason, the output from your code will be in error, and in the best case it will crash, with the worst case scenario of giving erroneous calculations that are not detected.
So the moral of the story is to always use a comma separated list?

One last question; is there a big difference performance-wise between selecting a single column from a table as opposed to selecting the whole row?

Thanks for all of the help and advice!
Learnin' n00b is offline
Reply With Quote
View Public Profile
 
Old 04-04-2011, 12:36 AM Re: Are static pages "easier" on a webserver then getting content from a database?
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Quote:
Originally Posted by Learnin' n00b View Post
Is MYSQL_NUM more efficient than MYSQL_ASSOC, or is there no difference?
There isn't any good reason to concern yourself with such a minor performance difference. Good design dictates that you should use ASSOC in most cases since the string indexes will be meaningful.

Quote:
Originally Posted by Learnin' n00b View Post
One last question; is there a big difference performance-wise between selecting a single column from a table as opposed to selecting the whole row?
Only select what you need. As far as I know there is no significant performance difference between SELECT * and specifying every column. I could be wrong, but in any case it is best to be as specific as possible.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE

Last edited by NullPointer; 04-04-2011 at 12:40 AM..
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 04-04-2011, 07:32 AM Re: Are static pages "easier" on a webserver then getting content from a database?
Super Spam Talker

Posts: 880
Name: Paul W
Trades: 0
"Only select what you need" is good advice - second bit of advice is to make the query do any processing whenever you can, for example ordering results in a certain way.

The reason you select as little as possible comes into play when you're querying large tables with lots of data to return - then you could find the db having to do lots of disk access and messing around with temp files before it returns the results. Probably not an issue for you but following best practice is always a good idea.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE


*** New:
Please login or register to view this content. Registration is FREE
PaulW is online now
Reply With Quote
View Public Profile
 
Old 04-04-2011, 07:36 AM Re: Are static pages "easier" on a webserver then getting content from a database?
Skilled Talker

Posts: 60
Trades: 0
I actually have better luck with static html pages rather than dynamic php database pages.
__________________

Please login or register to view this content. Registration is FREE
gameutopia is offline
Reply With Quote
View Public Profile Visit gameutopia's homepage!
 
Old 04-04-2011, 07:41 AM Re: Are static pages "easier" on a webserver then getting content from a database?
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,385
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
Better "luck"??????
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 04-04-2011, 09:39 PM Re: Are static pages "easier" on a webserver then getting content from a database?
Junior Talker

Posts: 1
Trades: 0
I find it easier to do a database site then doing it all through straight HTML. Mainly because instead of opening every html file and going to the correct lines and so on i can just open up PHPMyAdmin or Navicat or some other program to manage my SQL and go right to it quick and do the edit. If i do not do that i usually just code a edit form to update my pages with what i want.

I also find it easier on the system not a whole lot easier but it does run quicker if you tell the query what you are pulling vs *. Not also to mention if i am correct it also helps limit what shows if there is a flaw in the script to only show specific information instead of the whole row.
Enf0rcer is offline
Reply With Quote
View Public Profile
 
Old 04-09-2011, 04:17 PM Re: Are static pages "easier" on a webserver then getting content from a database?
Novice Talker

Posts: 5
Trades: 0
Also consider this:
  • INDEX you db columns:
    Say you have 1000 records with a column ´fruit_id' that record either one of: apple (fruit_id 1), pear (fruit_id 2), orange (fruit_id 3).
    |fruit_id|
    1
    3
    1
    2
    1
    1
    2
    2
    ....
    If you INDEX the column, the database query (let's say we are querying apples), will look for INDEX 1 and skip all other records.
    You can put INDEX on any column where it makes sense (do it from phpMyAdmin).
    http://www.tizag.com/mysqlTutorial/mysql-index.php
  • I know that people say that closing db connection is not necessary. I think it is. Close your connections as soon as possible.
  • I am doing a daily CRON JOB on my database that REPAIR and OPTIMIZE my database tables.
All together these simple procedures prevent the database to OVERHEAD.
__________________

Please login or register to view this content. Registration is FREE
iTower is offline
Reply With Quote
View Public Profile Visit iTower's homepage!
 
Old 04-20-2011, 08:18 AM Re: Are static pages "easier" on a webserver then getting content from a database?
writing_buddy's Avatar
Experienced Talker

Posts: 35
Trades: 0
yeah, i do agree too.. database, that is..

you see, if you really want to manipulate your content before you output them, it's difficult to maintain your website.. by using a database, (of course, with proper codes), you can make it work..

Do your best!
__________________

Please login or register to view this content. Registration is FREE
writing_buddy is offline
Reply With Quote
View Public Profile Visit writing_buddy's homepage!
 
Reply     « Reply to Are static pages "easier" on a webserver then getting content from a database?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.96708 seconds with 12 queries