Bup bip bop… a calcular… a calcular… a iniciar a sequência 42…

Bom, parece que aqueles robôs malucos estão outra vez a armar das suas! Assumiram o controlo desta página e traduziram-na para o idioma local do utilizador. No entanto, os robôs têm boas intenções e um grande coração (de metal). Apenas pretendem ajudar! Indique-nos como os robôs se estão a portar utilizando os botões na parte inferior da página. Aceder à versão em inglês
Estabelecer uma ligação à base de dados do MySQL utilizando CGI/Perl
Neste exemplo descreve utilizando CGI/Perl para estabelecer uma ligação à base de dados do MySQL.
#!/usr/bin/perl use cPanelUserConfig;
print "ContentType: text/html\n\n";
use DBI;
# Connecting to the database
# Replace DATABASENAME with the name of the database,
# HOSTNAME with the hostname/ip address of the MySQL server.
$drh = DBI->install_driver("mysql");
$dsn = "DBI:mysql:database=your_databasename;host=mysql.secureserver.net";
$dbh = DBI->connect($dsn,\'your_dbusername\',\'your_dbpassword\');
# Select the data and display to the browser
my $sth = $dbh->prepare("SELECT * FROM customers");
$sth->execute();
while (my $ref = $sth->fetchrow_hashref()) {
print "Found a row: id = $ref->{'id'}, name = $ref->{'name'}";
}
$sth->finish();
# Disconnect from the database.
$dbh->disconnect();
print "ContentType: text/html\n\n";
use DBI;
# Connecting to the database
# Replace DATABASENAME with the name of the database,
# HOSTNAME with the hostname/ip address of the MySQL server.
$drh = DBI->install_driver("mysql");
$dsn = "DBI:mysql:database=your_databasename;host=mysql.secureserver.net";
$dbh = DBI->connect($dsn,\'your_dbusername\',\'your_dbpassword\');
# Select the data and display to the browser
my $sth = $dbh->prepare("SELECT * FROM customers");
$sth->execute();
while (my $ref = $sth->fetchrow_hashref()) {
print "Found a row: id = $ref->{'id'}, name = $ref->{'name'}";
}
$sth->finish();
# Disconnect from the database.
$dbh->disconnect();