Jump to content

Bad performance


CyrusTh3VIrus

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.
Link to comment
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.
Link to comment
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.
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.