Jump to content

Please improve my MYSQL code...


foluska

Recommended Posts

my current code is way to slow. Also it looks memory extensive so please can you suggest improvements?

 

			for($i=0;$i<count($save);$i++) {
			$query .= ($i)?" OR id='".$save[$i]."'":" id='".$save[0]."'";
		}
		$res = mysql_query("SELECT * FROM my_table WHERE".$query);
		$numsav = mysql_affected_rows();
		if($res) {
			while($row = mysql_fetch_assoc($res)) {
				$doc = del_html(addslashes(@implode("",@file($row['link']))));
				if(!mysql_query("INSERT INTO saved_info (title, link, description, data, cat, pic) VALUES ('".addslashes($row['title'])."','".$row['link']."','".addslashes($row['description'])."','".$doc."','".$row['cat']."', '".$row['pic']."')")) {
				// echo mysql_error();
				$done += 1;
				echo "<br>". $done;
				}
			}
		};

Link to comment
https://forums.phpfreaks.com/topic/143416-please-improve-my-mysql-code/
Share on other sites

 

but i don't see why your code shouldn't work regardless off the  while loop

 

Create a multirow INSERT instead. <<<<< what this mean sorry.

 

 

can not remember where i read this but using the count in the loop can slow things down.

 

saying that i don't see any code there that will make a sever go slow at all.

 

WARNING

 

if this project out weighs your current database then it time to head for a dedicated database host.

 

Create a multirow INSERT instead. <<<<< what this mean sorry.

 

Consider

INSERT INTO table VALUES (v11,v21,v31);
INSERT INTO table VALUES (v12,v22,v32);
...
INSERT INTO table VALUES (v1n,v2n,v3n);

 

and

 

INSERT INTO table VALUES
(v11,v21,v31),
(v12,v22,v32),
...,
(v1n,v2n,v3n)

 

Which one will be faster? Running n queries each inserting one row, or one query inserting n rows at once?

 

Archived

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

×
×
  • 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.