2008-06-24 10:59:10大D QQ

perl mysql select

use DBI;
use strict;

##
#$http://xxxxxx/s001.php#
#
my $db=”db_item”;
my $host=’172.0.0.xxx’;
my $user=’use’;
my $password=’passswd’;

my $dbh = DBI->connect(”DBI:mysql:database=$db;host=$host”,
$user, $password, {RaiseError => 1});
if ($dbh) {
print ”connection success!!n”;
#
# mysql query
#
my $sth = $dbh->prepare(”SELECT * FROM tbl limit 10”);
$sth->execute();
while(my $ref = $sth->fetchrow_hashref()) {
print ”no: $ref->{’no’}n”;
print ”class: $ref->{’class’}n”;
print ”----------n”;
}

# clean up


}
else
{
# insert to db
die;

}
$dbh->disconnect();