Beefy Boxes and Bandwidth Generously Provided by pair Networks
XP is just a number
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
Here's (kind of) what I would do. Everything I do is explained in more detail in the DBI docs. Definitely read the section on placeholders. Not only does it handle quoting for you, it makes this easier by predefining an array with your column names.

I'm guessing the column names in the 1st DB are the same as the second DB.

## UNTESTED ## Setup the column names - This way when you need to change it, you o +nly change in one place ## The column names will also stay in order my @col_names = qw/reg pat ped adnasec impexp cveped adnaent cr +upimp rfcimp curpaa/; my $col_names_string = join(',',@col_names); my $dbhX1 = DBI->connect('dbi:XBase(RaiseError=1):'); my $select1 = $dbhX1->prepare("SELECT $col_names_string FROM r501"); $select1->execute(); ## Now we create the string with placholders. my $placeholders = join(',',map { '?' } @col_names ); my $sql = "INSERT INTO r501 ( $col_names_string ) VALUES ( $placehold +ers )"; ## We are going to call this quite a bit so lets prepare it out side o +f the loop my $sth = $mysql_dbh1->prepare( $sql ); while ( my @row = $select1->fetchrow_array() ){ ## Stick the result in the other database $sth->execute(@row); }
grep
One dead unjugged rabbit fish later...

In reply to Re: I got confuse with INSERT by grep
in thread I got confuse with INSERT by padawan_linuxero

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



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (4)
As of 2024-04-25 09:17 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found