# Use DBI to connect to the judoka_csv datafile #----------------------------------------------- my $dbh = DBI->connect('dbi:AnyData(RaiseError=>1):'); # tell DBI we want to use the Anydata module in ./MyLibs $dbh->func( 'judoka', 'CSV', 'data/judoka_csv', 'ad_catalog'); # Connect to the users_csv data file # select from the datafile the id for the user ID from the array paased from the previous sub routine my $sql_query = "SELECT * FROM judoka WHERE judoka_id = ?"; # this is the SQL command we want to execute my $sql_params = ($winner); # Theese are the parameteres we will use in the SQL command above print $query->p("$sql_query\n[$sql_params]\n") if $DEBUG; # if we are in debug mode print the SQL statement my $sth = $dbh->prepare( $sql_query ); # prepare the SQL command $sth->execute( $sql_params ); # excecute the SQL using our parameters my @winner_data = $sth->fetchrow_array; # this line takes the results of the select and puts it in the array called RESULTS $dbh->disconnect(); # we are done with the datbase for now, so disconnect from it (MAY NOT BE NECESSARY) print $query->p("result = ", @winner_data)if $DEBUG; # Prints the result of our SQL command if we are in debug mode. # grab the number of wins and then add one to it and insert back into the DB my $wins = $winner_data[10] + 1; print $query->p("winner =",$winner," and Wins = ", $wins)if $DEBUG; my $sql_insert ="UPDATE judoka SET wins = ? WHERE judoka_id = ?"; my @sql_insert_params = ($wins,$winner); print $query->p("$sql_insert\n[@sql_insert_params]\n") if $DEBUG; # if we are in debug mode print the SQL statement $sth = $dbh->prepare( $sql_insert ); # prepare the SQL command $sth->execute( @sql_insert_params ); # excecute the SQL using our parameters