Jump to content

[SOLVED] This is killing my database


Gayner

Recommended Posts

mysql_query("INSERT INTO `forum_replies` (`tid`,`uid`,`message`,`date`,`time`) VALUES('".$tid."','".$_SESSION['user_id']."','".$msg."','".$date."','".$time."')");
					mysql_query("UPDATE forum_topics   SET `time`='".time()."', ".
                                            "lastposttime='"         .time()          ."' ". 
										"WHERE id='"        .$tid               ."'") or die(mysql_error());

mysql_close();
					header("Location: ./index.php?act=topic&id=".$tid);

 

Iuno that's best code I can think off. whenever i run that on a form like

 

The queries work it's jsut it takes like 5-10 seconds to freakin submit the dam thing? normal ?? Should be instant? my other forum if u submit it it's instant.. why this all slow??

Link to comment
Share on other sites

By just glancing at the query it seems to be fine to me but there could be something else causing the query to be slow. It may be something else on the page, its hard to say without know what is going on. You can try this cleaner looking query and see if it helps any:

 

mysql_query("INSERT INTO forum_replies(tid,uid,message,date,time) VALUES('$tid','".$_SESSION['user_id']."','$msg','$date','$time')");

 

Not going to say it will be any faster but it at least looks nicer lol.

Link to comment
Share on other sites

By just glancing at the query it seems to be fine to me but there could be something else causing the query to be slow. It may be something else on the page, its hard to say without know what is going on. You can try this cleaner looking query and see if it helps any:

 

mysql_query("INSERT INTO forum_replies(tid,uid,message,date,time) VALUES('$tid','".$_SESSION['user_id']."','$msg','$date','$time')");

 

Not going to say it will be any faster but it at least looks nicer lol.

 

 

I Replaced it with a random one

 

 mysql_query("INSERT INTO `prays` (`title`,`prayer`,`private`,`level`,`time`,`nameid`) VALUES (
'". mysql_real_escape_string('1') ."',
'". mysql_real_escape_string('2') ."',
  '". mysql_real_escape_string('3') ."',
    '". mysql_real_escape_string('4') ."',
  '". mysql_real_escape_string('5') ."',
'". mysql_real_escape_string('6') ."');") or die(mysql_error()) ;

 

and it works perfect, but this is on a different table, is there something wrong my forum_replies table I posted a screenshot... hmm ???

Link to comment
Share on other sites

you could try seeing how long the query takes.. i.e.

function getmicrotime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}

$time_start = getmicrotime();

mysql_query("INSERT INTO forum_replies(tid,uid,message,date,time) VALUES('$tid','".$_SESSION['user_id']."','$msg','$date','$time')");

$time_end = getmicrotime();
$time = $time_end - $time_start;

echo "Query took $time seconds";

Link to comment
Share on other sites

Query took 8.80006599426 seconds

 

 

LOL but if i switch back to:

 

 mysql_query("INSERT INTO `prays` (`title`,`prayer`,`private`,`level`,`time`,`nameid`) VALUES (
'". mysql_real_escape_string('1') ."',
'". mysql_real_escape_string('2') ."',
  '". mysql_real_escape_string('3') ."',
    '". mysql_real_escape_string('4') ."',
  '". mysql_real_escape_string('5') ."',
'". mysql_real_escape_string('6') ."');") or die(mysql_error()) ;

 

It only takes:

Query took 0.000324964523315 seconds

 

 

 

WTH??

 

It has to be something to do with my table forum_replies..

 

iuno wth omg

 

Link to comment
Share on other sites

The table looks fine. It could be the amount of data in the table but I doubt it. One thing I did notice is that you are storing the date as a varchar. I am not sure why you are doing that because you can use either mysql's date or datetime or even php's time(); functions to store the time. I usually use php's time() function with an int as the field type. Its really easy to work with timestamps and you can even get dates from them.

Link to comment
Share on other sites

The table looks fine. It could be the amount of data in the table but I doubt it. One thing I did notice is that you are storing the date as a varchar. I am not sure why you are doing that because you can use either mysql's date or datetime or even php's time(); functions to store the time. I usually use php's time() function with an int as the field type. Its really easy to work with timestamps and you can even get dates from them.

 

Hmm... true..

 

But I dont think any of this is worth 8seconds of insert query timeout? Can u please help me catch this problem bro.. thx

Link to comment
Share on other sites

The table looks fine. It could be the amount of data in the table but I doubt it. One thing I did notice is that you are storing the date as a varchar. I am not sure why you are doing that because you can use either mysql's date or datetime or even php's time(); functions to store the time. I usually use php's time() function with an int as the field type. Its really easy to work with timestamps and you can even get dates from them.

 

Hmm... true..

 

But I dont think any of this is worth 8seconds of insert query timeout? Can u please help me catch this problem bro.. thanks

 

 

Sorry it wont let me edit.

 

but this is the query not the update function one.

 

mysql_query("INSERT INTO `forum_replies` (`tid`,`uid`,`message`,`date`,`time`) VALUES('".$tid."','".$_SESSION['user_id']."','".$msg."','".$date."','".$time."')");

Link to comment
Share on other sites

try this and see how it goes for time... you don't have any triggers etc set up in your mysql database?

 

function getmicrotime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}

$time_start = getmicrotime();

mysql_query("INSERT INTO forum_replies(tid,uid,message,date,time) VALUES('1','2','3','4','5')");

$time_end = getmicrotime();
$time = $time_end - $time_start;

echo "Query took $time seconds";

 

 

Link to comment
Share on other sites

try this and see how it goes for time... you don't have any triggers etc set up in your mysql database?

 

function getmicrotime(){
list($usec, $sec) = explode(" ",microtime());
return ((float)$usec + (float)$sec);
}

$time_start = getmicrotime();

mysql_query("INSERT INTO forum_replies(tid,uid,message,date,time) VALUES('1','2','3','4','5')");

$time_end = getmicrotime();
$time = $time_end - $time_start;

echo "Query took $time seconds";

 

here:

 

Query took 6.25345611572 seconds and in database looks like this:

 

It insert data fine but took 7seconds lawl..

 

 

wat the hell is this mean?

 

 

Indexes: Documentation Keyname Type Cardinality Action Field

PRIMARY PRIMARY 102  Edit Drop id

 

Im looking at Structure and I see Cardinality is 102?

 

 

 

Even tho that wont make a difference but what the hell is wrong with my table, lol

 

 

 

 

If this make any difference this was the query i oringally used to make the table

 

CREATE TABLE `forum_replies` (

  `id` int(11) NOT NULL auto_increment,

  `tid` int(11) NOT NULL,

  `uid` int(11) NOT NULL,

  `message` text NOT NULL,

  `date` varchar(64) NOT NULL,

  `time` int(25) NOT NULL,

  `edit_time` int(24) NOT NULL,

  PRIMARY KEY  (`id`)

) ENGINE=InnoDB  DEFAULT CHARSET=latin1;

 

ENGINE=InnoDB is this why? Charset=Latin1 is this problem too ? lol

 

 

I think InnoDB Is the proble, how do i change it back tonormal mysql in phpmyadmin ?

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.