Advertisement
dev017

dbi with perl

Jan 2nd, 2024
586
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.40 KB | None | 0 0
  1. use DBI;
  2.  
  3. my $dsn = "DBI:mysql:database=testdb;host=localhost";
  4. my $user = "username";
  5. my $password = "password";
  6.  
  7. my $dbh = DBI->connect($dsn, $user, $password) or die "Não foi possível conectar ao banco de dados: $DBI::errstr";
  8.  
  9. my $sth = $dbh->prepare("SELECT * FROM tabela");
  10. $sth->execute();
  11.  
  12. while (my $row = $sth->fetchrow_arrayref) {
  13.     print "@$row\n";
  14. }
  15.  
  16. $dbh->disconnect();
  17.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement