Perl and Mysql
Quick guide to using perl with the mysql database
The perl DBI interface to mysql actually works!

Here are my notes.  
Below are the commands for

    - creating a database
    - creating a template for a table
    - adding fields into the table
    - creating users and giving them rights to your table
    - using the DBI interface from perl to access the table.



mysql -u root -p
        Logs you into mysql as root.  
        Of course the UNIX root is completely different than the mysql root.

create database example;
        Creates a database called example

use example;
        Switches to the database called example

CREATE TABLE mytable (
  -> name CHAR(30),
  -> phone CHAR(10)
  -> );
        This creates a template for a table with two fields: name,phone

INSERT INTO mytable VALUES ("Homer Simpson", "555-1234");
        This inserts the line:  Homer Simpson, 555-1234
                into the table called mytable

SELECT * FROM mytable;
        This prints the table called mytable

GRANT usage
  -> ON example.*
  -> TO test@localhost;
        This creates a user call test who can only connect from localhost

GRANT select, insert, delete
  -> ON example.*
  -> TO test@localhost;
        This gives select, insert, and delete permission to user:

        This exits the mysql session


        This script logs into the mysql
        database called example as
        user test who has password test

        It prints out the contents of mytable
        using the DBI interface.



use DBI;

$dbh = DBI->connect('dbi:mysql:example','testx','testx');

$sql = "select * from mytable";

$sth = $dbh->prepare($sql);

$sth->execute ||
           die "Could not execute SQL statement ... maybe invalid?";

#output database results
while (@row=$sth->fetchrow_array)
    { print "@row\n" }

Media Lab Overview
LIACS Homepage
MM Conf
ACM Multimedia
Science Direct
IEEE Library
LIACS Publications
ACM Digital Library