Salut,
Voici un exemple en local
1. La base mysql
lami20j@debian:~/trash/ccm_perl$ mysql -u root -p'azertyuiop' Personne
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 46
Server version: 5.0.51a-24+lenny1 (Debian)
Type 'help;' or '\h' for help. Type '\c' to clear the buffer.
mysql> show tables;
+--------------------+
| Tables_in_Personne |
+--------------------+
| Utilisateur |
+--------------------+
1 row in set (0.00 sec)
mysql> desc Utilisateur;
+--------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+----------+------+-----+---------+-------+
| nom | char(50) | YES | | NULL | |
| prenom | char(50) | YES | | NULL | |
| age | int(11) | YES | | NULL | |
+--------+----------+------+-----+---------+-------+
3 rows in set (0.00 sec)
mysql> select * from Utilisateur;
+--------+--------+------+
| nom | prenom | age |
+--------+--------+------+
| azerty | aaa | 10 |
| qwerty | bbb | 20 |
+--------+--------+------+
2 rows in set (0.00 sec)
mysql> exit
Bye
2. Le script + résultat
lami20j@debian:~/trash/ccm_perl$ cat dbi_view.pl
#! /usr/bin/perl
use DBI;
use strict;use warnings;
my $mysql_sock='/var/run/mysqld/mysqld.sock';
my $base = 'Personne';
my $host = 'localhost';
my $user = 'root';
my $pass = 'azertyuiop';
# connexion base de données
my $db_=DBI->connect("DBI:mysql:database=$base;host=$host;mysql_socket=$mysql_sock",$user,$pass);
# lire la table (préparation de la requête SELECT)
my $query=$db_->prepare("SELECT nom, prenom, age FROM Utilisateur");
# exécution de la requête
$query->execute();
# affiche les résultats
while (my ($nom, $prenom, $age)=$query->fetchrow_array){
print "$nom\t$prenom\t$age\n";
}
__END__
lami20j@debian:~/trash/ccm_perl$ perl dbi_view.pl
azerty aaa 10
qwerty bbb 20
106485010510997108