Hello Monks, first at all, great job you are doing here ! And here is my problem/question: We are creating a little mysqlserver for our tables. Now I have to write a module to get information into the table. I have already done an insert, but I also need an update. The problem is I don't know the colums sometimes. For example sometimes I have 2 columns, then 3........ Here is my example module (the table is column tab1, column tab2, the data is an 1000 rows csv file 6666666:Y)
# 1. INSERT INTO TABLE # 2. SELECT FROM TABLE sub insert_tab { $db = @_[0]; $table = @_[1]; @TAB = split (/ /,@_[2]); @VALUES = split (/ /,@_[3]); @VAL = (); foreach $i (@VALUES) { push (@VAL,"\'".$i."\'"); } $fieldlist = join (",", @TAB); $fieldvalues = join (",", @VAL); $con = "DBI:mysql:$db"; $user = "root"; $passwort = "pass"; $dbh = DBI->connect("$con","$user","$passwort") || die "DB connect +ion not made: $DBI_errstr"; $sql = qq{ insert into $table ($fieldlist) values ($fieldvalues) o +n duplicate key update }; #$sql = qq{ insert into $table ($fieldlist) values ($fieldvalues) +}; $sth = $dbh->prepare($sql); $sth->execute(); $sth->finish(); $dbh->disconnect(); } return 1;
I hope you can help me.

In reply to Mysql and Perl Module by endymion

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.