This is straight from the DBI docs:

The typical method call sequence for a SELECT statement is: 

  prepare,
    execute, fetch, fetch, ...
    execute, fetch, fetch, ...
    execute, fetch, fetch, ...


for example: 

  $sth = $dbh->prepare("SELECT foo, bar FROM table WHERE baz=?");

  $sth->execute( $baz );

  while ( @row = $sth->fetchrow_array ) {
    print "@row\n";
  }


The typical method call sequence for a non-SELECT statement is: 

  prepare,
    execute,
    execute,
    execute.


for example: 

  $sth = $dbh->prepare("INSERT INTO table(foo,bar,baz) VALUES (?,?,?)");

  while(<CSV>) {
    chomp;
    my ($foo,$bar,$baz) = split /,/;
        $sth->execute( $foo, $bar, $baz );
  }


The do() method can be used for non repeated non-SELECT statement (or with drivers 
that don't support placeholders): 

  $rows_affected = $dbh->do("UPDATE your_table SET foo = foo + 1");

In general:
You connect to your database (not table). Then you create your SQL 
statement....usually one of SELECT (for retrieving), INSERT (add a row), UPDATE (edit 
a row(s)), or DELETE (remove a row(s)). You then "prepare" the statement which does 
syntax checking, placeholder initialization, etc.  Then you execute your statement, 
which will return a result, that result will either be a success code or a set of rows 
retrieved.

In the case of a set of rows you then step through the rows using a while on the 
statement handle retrieving (hopefully) a reference (hash) to the contents of that row 
then doing whatever you want with the row.

Beyond this you will have to supply some specifics about your table structure(s), and 
what you are trying to accomplish.


------------------------------------------------
On Tue, 24 Sep 2002 12:45:58 +0100, "dan" <[EMAIL PROTECTED]> wrote:

> Finally I managed to get my perl script to connect to the relevant MySQL
> database. I've looked at the DBI.pm information, but I still am pretty
> clueless about how you read data from a table, and write data to it. Any
> help much appreciated.
> 
> Dan
> 
> 
> 
> -- 
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
> 

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to