Perl Tutorials - Herong's Tutorial Examples
∟Using MySQL Database Server
∟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) 1999 by Dr. Herong Yang, http://www.herongyang.com/ # 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:
\perl\bin\perl HelloMySQL.pl Hello world!
Congratulations, all required software and additional modules are working.
Table of Contents
About This Book
Perl on Linux Systems
ActivePerl on Windows Systems
Data Types: Values and Variables
Expressions, Operations and Simple Statements
User Defined Subroutines
Perl Built-in Debugger
Name Spaces and Perl Module Files
Symbolic (or Soft) References
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 Files in Binary Mode
Open Directories and Read File Names
File System Functions and Operations
Converting Perl Script to Executable Binary
Using DBM Database Files
►Using MySQL Database Server
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
XML Communication Model
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
References
Printable Copy - PDF Version