How to convert an excel to MySQL database.

Discussion in 'PHP' started by neriok, May 16, 2007.

  1. #1
    Help me.
    How to convert an excel to MySQL database.
    Or any cracket program?:(
     
    neriok, May 16, 2007 IP
  2. commandos

    commandos Notable Member

    Messages:
    3,648
    Likes Received:
    329
    Best Answers:
    0
    Trophy Points:
    280
    #2
    what is the format of ur excell ?

    you can convert it to csv u will have a format like this :

    fiel1 , field 2 , field 3 .... etc

    then u can using textpad add the query

    to convert to : insert... (field1 , ....,field3);
     
    commandos, May 16, 2007 IP
  3. neriok

    neriok Peon

    Messages:
    20
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Ok commandos.thnx.
    But I don't understand again.
    Example. I have a telephony numeratory database in excel 2003,and i want to build a code to wiew or search this numbers.
    I have 40 Databases in excel(each for one city),each of those have 4 columns:NAME,SURNAME,TEL. NUMBER,ADDRES.

    I have posibility to take this database from my oracle Server in,txt,access,excel.But i dont know how to take in MySQL?
    Can u help me to build this code in php? :)
    Thakns at all.
     
    neriok, May 16, 2007 IP
  4. gfreeman

    gfreeman Peon

    Messages:
    40
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #4
    I used this to read in a flat text file to a mySQL database:

    <?php
    
    echo"Slurp begins ...<P>\n";
    
    //Read in the data to an array
    
    $nameFile = './data/Nations.txt';
    
    $allNations = @file("$nameFile");
    
    //Loop through each entry/string in the array
    foreach ($allNations as $nationString) {
    
    //In this case, the text files contains lines formatted thus:
    //AF AFG 004 Afghanistan
    //So we need to split the string
    $split=(explode(' ', $nationString, 4));
    $a1=$split[0];
    $a2=$split[1];
    $a3=$split[2];
    $a4=$split[3];
    
    //Write the data
    		$sql="INSERT INTO atlas (atlas2letter, atlas3letter, atlasCode, atlasName) VALUES ('{$a1}', '{$a2}', '{$a3}', '{$a4}')";
    		do_sql($sql);
    }
    
    echo"Done";
    
    ?>
    Code (markup):
    If you save the excel files as a csv you can use this by tweaking the explode bit to delimit by commas rather than spaces
     
    gfreeman, May 16, 2007 IP
  5. donteatchicken

    donteatchicken Well-Known Member

    Messages:
    432
    Likes Received:
    28
    Best Answers:
    0
    Trophy Points:
    118
    #5
    donteatchicken, May 16, 2007 IP