Results 1 to 4 of 4

Thread: Problem in importing files from xml files to mysql

  1. #1
    Join Date
    Oct 2011
    Posts
    39
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default Problem in importing files from xml files to mysql

    Hi

    I have a problem in importing .xml files in my mysql database. my .xml file is also more than 3mb, so i change in my php.ini the upload_max_filesize = from 2MB to 100MB and also i change the max_execution_time = from 30 to 1200

    but still i cannot import my .xml files.

    no error displayed so i cannot configured out.

    here is my code for the import:

    Code:
    <?php
    
    $data = array();
    $con = mysql_connect("localhost", "root","");
    if (!$con) { 
      die(mysql_error());
    }
    $db = mysql_select_db("payroll", $con);
    if (!$db) { 
      die(mysql_error());
    }
    
    $sql = "select * from regular_dtr";
    $result =  mysql_query($sql, $con);
    if (!$result) {
        die(mysql_error());
    }
    
    function add_employee($EMP_NO, $Date, $DTR)
      {
          global $data; 
          
          $con = mysql_connect("localhost", "root","");
          if (!$con){ die(mysql_error());}
          $db = mysql_select_db("payroll", $con);
          if (!$db) { 
              die(mysql_error());
          }
    
          $EMP_NO = $EMP_NO;
          $Date = $Date;
          $Date = substr($Date,0,-13);
          $DTR = $DTR;
     
         $sql = "INSERT INTO regular_dtr (EMP_NO, DATE_DTR, DTR) VALUES ('$EMP_NO', '$Date', '$DTR')";
          mysql_query($sql, $con);
          
          $data []= array('EMP_NO' => $EMP_NO, 'DATE_DTR' => $Date, 'DTR' => $DTR); 
      }
      
      if ( $_FILES['file']['tmp_name'] )
      {
          $dom = DOMDocument::load( $_FILES['file']['tmp_name']);
          //ini_set('memory_limit', '150MB');   
          $rows = $dom->getElementsByTagName( 'Row' );
          global $last_row;
          $last_row = false;
          $first_row = true;
          foreach ($rows as $row)
          {
              if ( !$first_row )
              {
                  $EMP_NO = "";
                  $Date = "";
                  $DTR = "";
                  
                  $index = 1;
                  $cells = $row->getElementsByTagName( 'Cell' );
              
                  foreach( $cells as $cell )
                  { 
                      $ind = $cell->getAttribute( 'Index' );
                      if ( $ind != null ) $index = $ind;
                      
                      if ( $index == 1 ) $EMP_NO = $cell->nodeValue;
                      if ( $index == 2 ) $Date = $cell->nodeValue;
                      if ( $index == 3 ) $DTR = $cell->nodeValue;
                      $index += 1;
                  }
                 if ($EMP_NO=='' and $Date=='' and $DTR=='') {
                        $last_row = true;
                  }      
                  else {
                        add_employee($EMP_NO, $Date, $DTR);
    
                  }      
              }
              if ($last_row==true) {
                  $first_row = true;
              }     
              else {
                  $first_row = false;
              }
          }
      }
    ?>
    and
    Code:
    <html>
    <body>
    <form enctype="multipart/form-data" 
      action="import_reg_att.php" method="post">
      <input type="hidden" name="MAX_FILE_SIZE"/>
      <table width="600">
      <tr>
      <td>Employee Attendance:</td>
      <td><input type="file" name="file" /></td>
      <td><input type="submit" value="Upload" /></td>
      </tr>
      </table>
      </form>
      </body>
     </html>
    I hope someone can help me..cause i need to solve it urgently..

    I tried to search solution and when I tried like the editing php.ini, it did not work.


    Thank you

  2. #2
    Join Date
    Oct 2008
    Posts
    60
    Thanks
    2
    Thanked 7 Times in 7 Posts

    Default

    in php.ini change the post_max_size. Then most important, you have to RESTART apache webserver. Also, make sure you have the column in MySQL set to BLOB.

    Here is a great tutorial that i used to achieve this.

    http://www.php-mysql-tutorial.com/wi...-database.aspx

  3. The Following User Says Thank You to fobos For This Useful Post:

    newphpcoder (12-14-2011)

  4. #3
    Join Date
    Oct 2011
    Posts
    39
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Default

    I already change the post_max_size but still it did notwork...what is the used of BLOB?


    Thank you

  5. #4
    Join Date
    Oct 2008
    Posts
    60
    Thanks
    2
    Thanked 7 Times in 7 Posts

    Default

    A BLOB is a binary large object that can hold a variable amount of data. The four BLOB types are TINYBLOB, BLOB, MEDIUMBLOB, and LONGBLOB. These differ only in the maximum length of the values they can hold. The four TEXT types are TINYTEXT, TEXT, MEDIUMTEXT, and LONGTEXT. These correspond to the four BLOB types and have the same maximum lengths and storage requirements. See Section 10.5, “Data Type Storage Requirements”.

    BLOB values are treated as binary strings (byte strings). They have no character set, and sorting and comparison are based on the numeric values of the bytes in column values. TEXT values are treated as nonbinary strings (character strings). They have a character set, and values are sorted and compared based on the collation of the character set.

    And again, make sure these are changed.

    file_uploads 1GB
    upload_max_filesize 1GB
    max_input_time 999
    memory_limit 1GB
    max_execution_time 999
    post_max_size 1GB

  6. The Following User Says Thank You to fobos For This Useful Post:

    newphpcoder (12-16-2011)

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •