Mysql table crash

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • moazam
    New Member
    • Oct 2007
    • 11

    Mysql table crash

    Hi,
    I am experiencing table crash problem in my sql.. I have insert code that cause the table crash.. see this code

    Code:
    $a = mysql_query("INSERT INTO online(session_id,odate) VALUES('$sess','NOW()')");
    @mysql_free_result($a);
    whats wrong with this? before this code I was simply executing mysql_query(... ) .. I thought this could be due to not releasing resultset.

    Any help will be much appreciated..

    Thanks,
    Moazam
  • ak1dnar
    Recognized Expert Top Contributor
    • Jan 2007
    • 1584

    #2
    Originally posted by moazam
    Hi,
    I am experiencing table crash problem in my sql.. I have insert code that cause the table crash.. see this code

    Code:
    $a = mysql_query("INSERT INTO online(session_id,odate) VALUES('$sess','NOW()')");
    @mysql_free_result($a);
    whats wrong with this? before this code I was simply executing mysql_query(... ) .. I thought this could be due to not releasing resultset.

    Any help will be much appreciated..

    Thanks,
    Moazam

    What kind of table crash is this? have you lost any records or....

    Comment

    • Atli
      Recognized Expert Expert
      • Nov 2006
      • 5062

      #3
      Hi Moazam. Welcome to The Scripts!

      What do you mean by 'table crash'?

      The only thing I can see wrong there is that you use quote-marks around the NOW() function, which you shouldn't. Quote-marks should only be used with string values and dates.

      Also, if the session_id is really an ID, I would assume it is an Integer? If so then you should not use quote-marks in that either.

      Comment

      • Motoma
        Recognized Expert Specialist
        • Jan 2007
        • 3236

        #4
        Originally posted by moazam
        Hi,
        I am experiencing table crash problem in my sql.. I have insert code that cause the table crash.. see this code

        Code:
        $a = mysql_query("INSERT INTO online(session_id,odate) VALUES('$sess','NOW()')");
        @mysql_free_result($a);
        whats wrong with this? before this code I was simply executing mysql_query(... ) .. I thought this could be due to not releasing resultset.

        Any help will be much appreciated..

        Thanks,
        Moazam
        I think we are all confused as to the problem you are having. One thing to note is that the @ symbol in front of mysql_free_resu lt will prevent any error from being presented to the screen.

        Comment

        • moazam
          New Member
          • Oct 2007
          • 11

          #5
          Sorry for creating confusion.. here is the actual code
          Code:
          <?php
          function fill_online() {
          global $USER, GET_CONFIG;
          $query = "SELECT * FROM online WHERE `session_id` = '" . session_id() . "'";
          $result = mysql_query( $query );
          
          $ip = $_SERVER['REMOTE_ADDR'];
          $page = $_SERVER['REQUEST_URI'];
          $browser = $_SERVER['HTTP_USER_AGENT'];
          
          if( $result && mysql_num_rows( $result ) )
          {
          $user_field = '';
          if($USER!= '') {
          $user_field = "`user`='$USER',";
          }
          else {
          $user_field = "`user`='',";
          }
          $query = "UPDATE `online`
          SET
          $user_field
          `browser` = '$browser',
          `ip` = ' $ip',
          `time` = '".date("YmdHi")."'
          WHERE `session_id` = '" . session_id() . "'";
          mysql_query($query);
          }
          else {
          if ($USER!= '') {
          $query = "INSERT INTO `online` (`session_id`, `user`, `time`, `ip`, `browser`, `page`)
          VALUES('".session_id()."','$USER','". date( "YmdHi" )."','$ip','$browser','$page')";
          }
          else {
          $query = "INSERT INTO `online` (`session_id`, `time`, `ip`, `browser`, `page`)
          VALUES('".session_id()."', '". date( "YmdHi" )."','$ip','$browser','$page')";
          }
          mysql_query($query);
          }
          @mysql_free_result($result);
          
          //DELETE
          $now = date("YmdHi"); // yyyymmddhhmm, ex. 200009021431
          $timer_ago = date("YmdHi", mktime(date("H"), date("i") - $GET_CONFIG['max_time_online'], 0,
          date("m"), date("d"), date("Y")));
          $query = "DELETE FROM `online` WHERE `time` < '" . $timer_ago ."'";
          mysql_query($query);
          
          }
          ?>
          works fine with 100+ online users at a time.. but when user number grows.. table online crash.. and mysql says Table 'online' is marked as crashed and should be repaired

          Comment

          • pbmods
            Recognized Expert Expert
            • Apr 2007
            • 5821

            #6
            Heya, moazam.

            Time to repair your table.

            Comment

            • moazam
              New Member
              • Oct 2007
              • 11

              #7
              thats what I am doing all the time

              Comment

              • pbmods
                Recognized Expert Expert
                • Apr 2007
                • 5821

                #8
                Heya, moazam.

                Try backing up your database, deleting it and recreating it.

                Comment

                Working...