Jump to content


Photo

Bad performance


  • Please log in to reply
5 replies to this topic

#1 CyrusTh3VIrus

CyrusTh3VIrus
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 08 March 2006 - 11:20 PM

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.

#2 CyrusTh3VIrus

CyrusTh3VIrus
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 09 March 2006 - 11:19 PM

bump...

#3 wickning1

wickning1
  • Members
  • PipPipPip
  • Advanced Member
  • 405 posts

Posted 10 March 2006 - 12:27 AM

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.

#4 joecooper

joecooper
  • Members
  • PipPipPip
  • Advanced Member
  • 358 posts

Posted 10 March 2006 - 12:27 AM

you made little sence there, i guess thats why people arnt replying
Signature:
[/a]
[a href="http://www.planet-so...=1999&lngWId=8" target="_blank"]EzLogin 1.0[/a]
[a href="http://www.essexracers.com" target="_blank"]Essexracers.com[/a]
Msn Messenger: joe@joeyjoe.co.uk

#5 CyrusTh3VIrus

CyrusTh3VIrus
  • New Members
  • Pip
  • Newbie
  • 5 posts

Posted 10 March 2006 - 09:58 PM

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.


#6 wickning1

wickning1
  • Members
  • PipPipPip
  • Advanced Member
  • 405 posts

Posted 11 March 2006 - 01:04 AM

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.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users