Perl Tutorials - Herong's Tutorial Examples - v6.01, by Dr. Herong Yang
HelloMySQL.pl - My First Perl Program with MySQL
This section describes a tutorial example on how use the DBI->connect() function to connect Perl scripts to MySQL database server.
Now we are ready to write a Perl program using the DBI module to access MySQL server. Here my first example, HelloMySQL.pl:
# HelloMySQL.pl #- Copyright (c) HerongYang.com. All Rights Reserved. # use DBI; $dbh = DBI->connect("DBI:mysql:test"); $dbh->do("create table hello (message varchar(80))"); $dbh->do("insert into hello (message) values ('Hello world!')"); $sth = $dbh->prepare("select * from hello"); $sth->execute(); while ((@row) = $sth->fetchrow_array()) { print "$row[0]\n"; } $sth->finish(); $dbh->do("drop table hello"); $dbh->disconnect(); exit;
Let's start MySQL server, and run HelloMySQL.pl:
herong> perl HelloMySQL.pl Hello world!
Congratulations, all required software and additional modules are working.
Table of Contents
Data Types: Values and Variables
Expressions, Operations and Simple Statements
Name Spaces and Perl Module Files
Hard References - Addresses of Memory Objects
Objects (or References) and Classes (or Packages)
Typeglob and Importing Identifiers from Other Packages
String Built-in Functions and Performance
File Handles and Data Input/Output
Open Directories and Read File Names
File System Functions and Operations
Installing Database Module for MySQL
►HelloMySQL.pl - My First Perl Program with MySQL
Socket Communication Over the Internet
XML::Simple Module - XML Parser and Generator
SOAP::Lite - SOAP Server-Client Communication Module
Perl Programs as IIS Server CGI Scripts
CGI (Common Gateway Interface)
XML-RPC - Remote Procedure Call with XML and HTTP
RPC::XML - Perl Implementation of XML-RPC
Integrating Perl with Apache Web Server
CGI.pm Module for Building Web Pages
LWP::UserAgent and Web Site Testing
Converting Perl Script to Executable Binary