Cristina Durana wrote:
>
> Hi all!
> I have the following code but it doesn't work very well because I can't have
> the number of new rows neither with select * ... nor select count(*)...
> How can i do it?
>
> #---------------------------------------------------------------------------
> ------
> (...)
>
> my $dbh1 = Mysql->connect;
>
> #choose a database
> $dbh1->selectdb("dsi");
>
> #$command2 = "";
> $command2 = "select ninterno from participante where dsemail = '$email'";
> #$command2 = "select count(*) from participante where dsemail = '$email'";
>
> #Send the query to the relational database(Mysql)
> my $sth1 =
> $dbh1->query($command2);
>
> $nlinhas = $sth1->numrows;
>
> #disconnected from BD
> $rc1 = $dbh1->disconnect;
>
> if ($nlinhas == 0)
> {
> #$linhas =0; => new email!!!
>
> #Create a counter
> $countfile = "contador.dat";
>
> #open contador.dat to read
> open(COUNTER, "$countfile") || die "Don't open contador.dat: $!\n";
>
> #read the corrent value
> $count = <COUNTER>;
>
> close(COUNTER);
>
> if ($count =~ /\n$/) {
> chop($count);
> }
>
> $count++;
>
> #open file to write
> open(COUNTER,">$countfile") || die "Nao abre o ficheiro contador.dat p/
> escrita: $!\n";
>
> #write the value to file
> print COUNTER "$count";
>
> close (COUNTER);
>
> #insert into BD each new person
>
> $database = 'dsi';
> $user = 'cdurana';
> $password = 'mysql';
>
> $dbh = DBI->connect("DBI:mysql:$database", $user, $password);
>
> $command2 = "";
> $command2 = "insert into participante
> (ninterno,dsnome,dsapelido,dsmorada,dsemail) values
> ('$count','$nome','$apelido','$morada','$email')";
>
> $sth = $dbh->prepare($command2);
> $rv = $sth->execute;
>
> $rc = $dbh->disconnect;
> }
> else
> {
> print "<table border=\"0\" width=\"100%\" cellspacing=\"0\"
> cellpadding=\"0\
> \">";
> print "<tr>";
> print "<td width=\"100\"></td>";
> print "<td width=\"85%\"><div
> align=\"center\"><center><table
> border=\"1\"c\
> \
> ellpadding=\"5\" cellspacing=\"1\" width=\"57%\" bgcolor=\"#C0C0C0\">";
> print "<tr>";
> print "<td align=\"left\" width=\"66%\" bgcolor=\"#E1DEC6\"
> height=\"1\"><p
> align=\"center\"><font face=\"Arial\"
> color=\"#408080\"><big><strong>Existe(m) $nlinhas Email(s)
> Repetido(s).
> </strong></big></font></td>";
> print "</tr>";
> print "</table>";
> print "</center></div><p align=\"left\"> ";
> print "<hr size=\"3\" color=\"#408080\">";
>
> exit;
> }
> #---------- Fim do CGI ------
> #---------------------------------------------------------------------------
> ------
> .___.
> / \
> | O _ O |
> / \_/ \
> .' / \ `.
> /~ | | ~\
> (_ | | _)
> ~ \ / ~
> __\_>-<_/__
> ~;/ \;~
>
> Cristina Durana
>
Not sure what you are trying to accomplish. If you need to know the
number of rows you have inserted in a loop, you can just use a Perl
variable to count them as they are inserted.
--
Sasha Pachev
http://www.sashanet.com/ (home)
http://www.direct1.com/ (work)