how to optimise a mysql table using php

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • baris22
    New Member
    • Jan 2010
    • 5

    how to optimise a mysql table using php

    I am deleting rows before inserting new one and i get Overhead problems. what can i do do repair the table after i delete the row. i have been trying for ages but i could not do it. this is the code for inserting.

    when i use OPTIMIZE TABLE item, it does not work.

    Code:
    		// delete before inserting //////////////////////////
    		
    		$query = "SELECT COUNT(*) as num FROM orderr WHERE order_reference_number='".$newReference."' ";
    	    $total_pages = mysql_fetch_array(mysql_query($query));
    		$total_pages = $total_pages[num];
    		
    		if ($total_pages = "1")
    		
    		{
    		
    		$sql="DELETE FROM orderr WHERE order_reference_number='".$newReference."' ";
    	   //echo $sql;
    	    mysql_query($sql);
    		
    		$sql="DELETE FROM item WHERE order_reference_number='".$newReference."' ";
    	   //echo $sql;
    	    mysql_query($sql);
    
    		}
    		
    		////////////////////////////////////////////////////
  • Atli
    Recognized Expert Expert
    • Nov 2006
    • 5062

    #2
    Hey.

    What do you mean by "Overhead problems"? Could you elaborate on what the problem is exactly.

    Why would you need to "repair" the table after a DELETE? Do you mean that you want to re-use an ID generated by a AUTO_INCREMENT column?
    Have you tried using the REPLACE command instead of deleting and inserting manually?

    Comment

    • baris22
      New Member
      • Jan 2010
      • 5

      #3
      ok. i managed to get it working.

      Code:
      [PHP]
      
              if ($newReference == "A001")
              {
              $opt = "OPTIMIZE TABLE item";
              $opt_table = mysql_query($opt); 
              }
      
      [/PHP]
      I have got another small question. how can i add "B001" , "C001" , "D001" , "E001" ........ and so on till "Z001" to this if statement.

      Comment

      Working...