Hi All,
I had a MySql DB and i needed to read the info from a certain table and store it into an Access database. So i wrote a script to do this and it worked so well that i thought i'll share it with you guys. You can also play around with it to have it work the other way around. Enjoy!
-Kiko
#!/perl/bin/perl -w use DBI; use Win32::ODBC; use User::pwent; # Global Variables my @statement; # Array of sql statements that will be used for Acce +ss my @row; # Array of table rows read from MySql my @message; # Array of error messages used for debugging Access # MySQL Connection my $dbh = DBI->connect('DBI:mysql:DBName:localhost', 'UserName', 'Password', { RaiseError => 1, AutoCommit => 1 }); # Access Connection my $connection=new Win32::ODBC("DSN=;UID=;PWD=;"); unless ($connection) { push @message,"Unable to connect to database!"; } push @message,$connection->Error; # Create the sql statement for MySql and execute it $sth = $dbh->prepare("SELECT url,title,keywords from addresses"); $sth->execute; while ((@row) = $sth->fetchrow_array) { # This is were we grab all the table rows from MySql and store the +m into # an array to be inserted into Access. push @statement,"INSERT INTO keywords (url, title, keywords) VALUE +S ('$row[0]', '$row[1]', '$row[2]')"; } # Execute sql statments and if there is an error report it foreach (@statement){ $connection->Sql($_); if ($connection->Error()){ print "\nERROR: \nThe SQL statement:</b>\n $_ \n\n<b>caused th +e error:</b>\n\n ",$connection->Error(); die(); } push @message,$connection->Error(); } # Close the Access DB Connection $connection->Close(); # Close the MySql DB connection $sth->finish; $dbh->disconnect;

In reply to Reading from MySql and Storing the info into Access by Kiko

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.