Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Sep 2002
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help converting txtdb to mysql

    I have been trying using Phpmyadmin, but no success.

    The textdb is CSV .

    Can anybody help?

  • #2
    mat
    mat is offline
    Regular Coder
    Join Date
    Jul 2002
    Posts
    199
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Can you show the format of this "txtdb" please? a few rows or something..

  • #3
    mat
    mat is offline
    Regular Coder
    Join Date
    Jul 2002
    Posts
    199
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You can use phpMyAdmin to do it if the .txt, .csv file is basically a hunk of SQL like this:


    CREATE TABLE `yourTableName` (
    `field1` int(2) NOT NULL auto_increment,
    `field2` varchar(25) NOT NULL default '',
    'field3` varchar(30) NOT NULL default '',
    );


    INSERT INTO yourTableName ('field1', 'field2', 'field3') Values ('value1', 'value2', 'value3'); \\ one of these for every row in the database


    But if it's just data like:

    value1,value2,value3
    value4,value5,value6
    ..

    Then as far as i know there is no way to import this using phpMyAdmin. One way that i would use if the .csv file is like above (just the data & no sql) would be to get mySQL-front and import the .csv file into that, thus creating a database, then once you can export this database as an sql file, copy/load what's in that sql file into phpmyadmin on you web host and yippee..


    mat,
    Last edited by mat; 09-13-2002 at 08:02 AM.

  • #4
    Regular Coder
    Join Date
    Jun 2002
    Location
    UK
    Posts
    577
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You could write a scriptlet that meanders through the file and outputs to the page in a format that can be cut'n'pasted to mysql.

    txt.file
    arg1,arg2,arg3,arg4,arg5
    brg1,brg2,brg3,brg4,brg5
    etc etc

    PHP Code:
    <?php
    $dbtxtfile 
    '../txtfiles/mytextfile.txt';
    $fp fopen($dbtxtfile,"r");
    while(
    $mdb fgetcsv ($fp1000",")) {
    // the line above reads each line of the file and attributes each comma (the "," bit) seperated argument to $mdb[numeric];

    echo '"INSERT INTO `tablename` (fieldname1,fieldname2,fieldname3,fieldname4,fieldname5) VALUES(\ \\''.$mdb[0].' ',\ \\''.$mdb[1].' ',\ \\''.$mdb[2].' ',\ \\''.$mdb[3].' ',\ \\''.$mdb[4].' ')";<br>
    '
    ;
    }
    fclose($fp);
    ?>
    That should (it was flytyped so might need some cleaning to parse properly) output to the page a formatted version of the file ready for updating a database. You could just add the values straight into the database rather than outputting as text to the page if you really wanted.

    note There are backslashes in the VALUES( bit ) to enable echoing out single quotes \ ''.$mdb[0].'\ ' sort of thing - the forum doesn't allow them with php syntax highlighting
    Last edited by Ökii; 09-13-2002 at 11:47 AM.
    Ökii - formerly pootergeist
    teckis - take your time and it'll save you time.


  •  

    Posting Permissions

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