Error Diagnostic Variables : MySql « Database « Perl

Home
Perl
1.Array
2.CGI
3.Class
4.Data Type
5.Database
6.File
7.GUI
8.Hash
9.Language Basics
10.Network
11.Regular Expression
12.Report
13.Statement
14.String
15.Subroutine
16.System Functions
17.Win32
18.XML
Perl » Database » MySql 
Error Diagnostic Variables
   

use DBI;
$driver="DBI:mysql";
$database="sample_db";
$user="root";
$host="localhost";

$dbh=DBI->connect('dbi:mysql:sample_db','root','password',{
             RaiseError => 1
             PrintError => 0
}
or die $DBI::errstr;

$sth=$dbh->prepare("SELECT name FROM Employee"or die "Can't prepare sql statement" . DBI->errstr;
$sth->execute();
while(my @val = $sth->fetchrow_array()){
    print "name=$val[0]\n";
}
print $sth->rows," rows were retrieved.\n";
$sth->finish();
$dbh->disconnect();

                      

   
    
    
  
Related examples in the same category
1.Deleting Entries
2.Dumping a Query's Results
3.Handling Quotes
4.Inserting into a Database
5.Load text file to database
6.MySQL Data Types
7.Preparing a Statement Handle and Fetching Results
8.Pushing Query Results to an Array to Find Wildcard Hosts
9.Query parameter binding
10.Retrieving Query Results Listing MySQL Users and Hosts
11.Retrieving an Index ID
java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.