Connessione MySQL e PERL | Altri linguaggi

Topic: Pubblico - Composto da 3 Posts di 2 Utenti.

12 Luglio, 2008 14:40 #1
jackal17
Utente

jackal17
Registrato: Jul, 2008
Posts: 6
Offline

Salve a tutti sto cercando un esempio di connessione MYSQL PERL, ma non riesco a trovare un esempio semplice, qualcuno potrebbe aiutarmi ?

Grazie


Aut Inveniam Viam Aut Faciam

12 Luglio, 2008 14:47 #2
g2d
Moderatore

g2d
Registrato: Jul, 2008
Posts: 957
Offline
Segui g2d su Twitter!

Ciao, googlando un pò ho trovato quest'esempio che mi sembra il più semplice:

#!/usr/bin/perl w
use strict;

# Load Modules
use DBI;
use CGI;


my $q = new CGI;

# Connect to MySQL
my $dbh = DBI->connect("DBI:mysql:mybook:localhost",
"username","password" )
|| die "Could not connect to database: "

. DBI->errstr;

my $sql_stmnt = "SELECT book_id, titolo, editore
FROM books
WHERE author = 'Dan Brown'";
my $sth = $dbh->prepare($sql_stmnt);

$sth->execute();

# Retrieve results and reference number
my $results = $sth->fetchall_arrayref();
$sth->finish();
$dbh->disconnect();

# Web page

print

$q->header(type=>'text/html' ),
$q->start_html;

# Loop through array of arrays

foreach my $record (

1$result){<br /><br />         # Parse each record array and display <br /><br />         my ($book_id, $titolo, $editore) =
$record;
print $q->a({href=>"book_detail.cgi?book_id=$book_id"},
"$titolo ($editore)" ), $q->br, "\n";
}


print $q->end_html;

exit;  

l'ho tratto dal sito http://www.unixreview.com/documents/s=8925/ur0312c/

Spero possa essere utile 8-)

Ultima modifica 11 Luglio, 2010 01:15 di root


Un tempo ero algweb ora sono g2d

12 Luglio, 2008 18:23 #3
jackal17
Utente

jackal17
Registrato: Jul, 2008
Posts: 6
Offline

Grazie Mille, la procedura da te indicata mi è stata molto utile.

Ciao Cool


Aut Inveniam Viam Aut Faciam

Condividi su:

Loggati o Registrati per replicare