Jump to content

Archived

This topic is now archived and is closed to further replies.

CyrusTh3VIrus

Bad performance

Recommended Posts

Lets say that i want to get a array of values from a database, like:
$sql = mysql_query(SELECT id, c1, c2, c3 FROM table WHERE id=1);
$result = mysql_fetch_assoc($sql);

But how much performance hit would it be to get the values from different tables like this:
$result['id'] = query and get ID
$result['c1'] = query and get c1
... and so on

Would that make a big performance hit, i know it would make a performance hit but would that a be a big performance hit? And also would it be faster to make sub querys in SQL rather than make a query for each value and is there any better way to acomplish this?

Sorry for my bad english.

Share this post


Link to post
Share on other sites
It really all depends on the specifics of your problem. There are a lot of strategies for increasing performance but we need to know what the data looks like. Spend a couple minutes describing your system, the data you store, the tables you've created, and what you'd like to do with them.

Sending a query to the database is one of the most expensive operations in a PHP script, especially if the database is on another server, so yes, it is important to try to limit the number of queries. However, you should be able to fire off at least a couple hundred per page without killing your site, as long as they are simple queries.

Share this post


Link to post
Share on other sites
Okej, im sorry if i wasent so clear what i want. I want to make system that stores dynamic information in the database that isent table specific. So if i want to make lets say a guestbook with that system insted of creating a table i want to fetch the guestbook data from different tables. Like this:

function postReply($name, $msg, $date) {
$id = make some uniq id here...
mysql_query("INSET INTO textVars(id,fieldname,value) values('".$id."','gb_name','".$name."')");
mysql_query("INSET INTO textVars(id,fieldname,value) values('".$id."','gb_msg','".$msg."')");
mysql_query("INSET INTO dateVars(id,fieldname,value) values('".$id."',''gb_date'','".$date."')");
}

What im trying to say is that i dont want to store data thats table specific.
So if i want to fetch a gb reply ill use this function:

function fetchReply($id) {
$data = array();
$data['id'] = $id;
$data['name'] = fetch row from textVars WHERE id=$id AND fieldname='gb_name'
$data['msg'] = fetch row from textVars WHERE id=$id AND fieldname='gb_msg'
... and so on
return $data;
}

Im wondering if this would make a big performance hit or if it would not so big and im also wondering if ther any better way to fetch data from differnt tables. I hope you understand what im trying to ask.

Share this post


Link to post
Share on other sites
You should fetch all rows WHERE id=$id and then go through them in php and determine what to do with each one depending on what fieldname is set to.

Share this post


Link to post
Share on other sites

×

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.