Microsoft Word - Sam's Teach Yourself MySQL in 21 Days - SAMS.doc

(singke) #1

Q&A


Q: (^) Why is the Perl DBI so powerful?
A:
One of the main reasons it is considered so powerful is because of its
simple yet elegant design. For example, you could create a database handle
to an Oracle database with one line of code. You could create a database
handle to a MySQL database in the next line of code. From there, you could
create two more statements that exchange data between two database. You
can do all that with maybe six lines of code. It doesn't get any easier than
that.
Q: (^) Am I limited to just simple SQL statements with the Perl DBI?
A:
No. You can issue any command with the Perl DBI that you could issue
from the MySQL Monitor. So statements, such as the OPTIMIZE and LOAD
DATA INFILE, are fair game. In fact, the database handle has a func()
method that allows you to pass statements such as CREATE database all
in one line. The syntax looks like the following:
$retVal = $dbh->func('createdb', database name, 'admin')
Other statements include the dropdb, shutdown, and reload
functions. These all follow pretty much the same syntax. The
shutdown and reload functions do not have the database name
argument that the createdb and dropdb have. They need to be
typed exactly as they appear in the previous code


Exercises



  1. Create a Perl script that takes a request from the user and displays values from the
    database based on the given value. For example, with the Meet_A_Geek database,
    create a Web page that allows a person to see a list of customers based on the
    states in which the customers live. Pass this value to a Perl script that uses that
    parameter in an SQL SELECT query.

  2. Create a Perl script that adds a user to the database. (Hint: use the GRANT
    statement).


Week 2 In Review


You've finished your second week of learning about MySQL. You have learned about populating your
database and using MySQL's intrinsic functions. You have also learned about programmatic interfaces and
what they can do for you.


Week 3: At a Glance


Day List


Day 15: MySQL and PHP
Day 16: MySQL and Time
Day 17: MySQL Database Security
Day 18: How MySQL Compares
Day 19: Administrating MySQL
Day 20: Optimizing MySQL
Day 21: Putting It All Together
Appendix A: SQL Syntax and Commands
Appendix B: Current MySQL Functions
Appendix C: Answers to Exercises

You've finished your second week of MySQL. You should know how to work with data that is stored in a
MySQL database. Now that you know how to manipulate the data, you will learn how to maintain the
database.

Free download pdf