This is a tab delimited text file. the format is: Real_filenametabname_of_gametabdescription_of_game
TCPpipe.exe TCPpipe A tool for viewing incoming traffic from rou +ter's forwarded ports! Process.exe Process A tool for viewing WinXP's Processes and it' +s dependencies! StressRelax.exe StressRelax Whip The Worker! Try it, its very fu +nny! Activate.exe Activate A very useful tool for cracking Windows an +d more! GoogleFS.exe GoogleFS A very handy tool to search Google for Fil +es! Speedtouch_Monitor.exe SpeedtouchMon Allows you to view inbound/ +outbound information from router!
The file above must be inserted to a mysql database automatically. Here is the code.
.... $dbh->do( "CREATE TABLE games (file varchar(30) primary key, name text +, description text, counter int)" ); ...... my @row; my $select = $dbh->prepare( 'SELECT COUNT(*) FROM games where name=?' +); my $insert = $dbh->prepare( 'INSERT INTO games (file, name, descriptio +n, counter) VALUES (?, ?, ?, ?)' ); my $update = $dbh->prepare( 'UPDATE games SET description=? where name +=?' ); open (FILE, '<../data/games/descriptions.txt') or die $!; while (<FILE>) { chomp; my ($name, $description) = split /\t/; $select->execute($name); my $count; while( my $ref = $select-> fetchrow_arrayref() ) { $count = $ref->[0]; } if( $count == 0 ) { #a new game $insert->execute( $file, $name, $description, 0 ); } else { $update->execute( $description, $name ); } } close (FILE);
The zero in insert statemnt is the counter that will be used later.
This script need only to eb executed once.
What am i doing wrong?

2006-04-17 Retitled by planetscape, as per Monastery guidelines
Original title: 'IHot to insert a tab delimited text file to a mysql database'


In reply to How to insert a tab delimited text file to a mysql database by Nik

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.