Perl
  Home arrow Perl arrow Page 2 - Creating a Database with Perl and DBI
Dev Shed Forums 
Administration  
Apache  
BrainDump  
DHTML  
Flash  
Java  
JavaScript  
Multimedia  
MySQL  
Oracle  
Perl  
PHP  
Practices  
Python  
Reviews  
Security  
Style-Sheets  
Web Services  
XML  
Zend  
Zope  
Forums Sitemap 
IBM® developerWorks 
Dedicated Servers 
E-Commerce Hosting 
Linux Web Hosting 
Managed Hosting 
Small Business Hosting 
Download TestComplete 
VPS Hosting 
Weekly Newsletter

 
Developer Updates  
Free Website Content 
IBM Developerworks
 RSS  Articles
 RSS  Forums
 RSS  All Feeds
Write For Us Get Paid 
Request Media Kit
Contact Us 
Site Map 
Privacy Policy 
Support 
 USERNAME
 
 PASSWORD
 
 
  >>> SIGN UP!  
  Lost Password? 
PERL

Creating a Database with Perl and DBI
By: Apress Publishing
  • Search For More Articles!
  • Disclaimer
  • Author Terms
  • Rating: 4 stars4 stars4 stars4 stars4 stars / 2
    2008-03-20

    Table of Contents:
  • Creating a Database with Perl and DBI
  • The DESCRIBE Command
  • The INSERT Command
  • The SELECT Command

  • Rate this Article: Poor Best 
      ADD THIS ARTICLE TO:
      Del.ici.ous Digg
      Blink Simpy
      Google Spurl
      Y! MyWeb Furl
    Email Me Similar Content When Posted
    Add Developer Shed Article Feed To Your Site
    Email Article To Friend
    Print Version Of Article
    PDF Version Of Article
     
     
     
    ADVERTISEMENT

    TestComplete™ automates software testing for a fraction of what the big guys charge. Easy functional and load testing for all Windows, .NET, Java and Web apps. Download a free trial now.

    Creating a Database with Perl and DBI - The DESCRIBE Command
    (Page 2 of 4 )

    TheDESCRIBEcommand shows all the fields in the table and their types. This will show us if themusicianstable was created correctly:

    mysql> DESCRIBE musicians;

     Field

     Type

     Null

     Key

     Default

     Extra

     player_id

     int(11)

     

    PRI

     0

     

     name

     char(50)

     YES

     

     NULL

     

     phone

     char(12)

     YES

     

     NULL

     

    3 rows in set (0.00 sec)

    This looks OK so far. Let’s create the other two tables:what_they_playandinstruments:

    mysql> CREATE what_they_play (
        ->   player_id INT,
       
    ->   
    inst_id INT);
    Query OK, 0 rows affected (0.01 sec)

    mysql> CREATE TABLE instruments (
       
    ->  inst_id INT PRIMARY KEY,
       
    ->  instrument CHAR(40),
       
    ->  type CHAR(20),
       
    ->  difficulty INT);
    Query OK, 0 rows affected (0.00 sec)

    Creating a Non-root User with the GRANT Command

    It is important to create a non-root user to access the database—performing normal non-MySQL-admin activities using the root user is a bad idea for security reasons. So let’s create a user that will be allowed to perform basic queries on themusicians_dbdatabase:

    mysql> GRANT SELECT, INSERT, UPDATE, DELETE
        ->   ON musicians_db.*
       
    ->  TO musicfan@localhost
       
    ->  IDENTIFIED BY "CrimsonKing";
    Query OK, 0 rows affected (0.03 sec)

    You can trust us when we say that this command creates a user namedmusicfan with a password “CrimsonKing”5 and grants this user permission to select, insert, update, and delete records from the database. Or, you can check out the documentation and read all about theGRANTcommand.

    We are going to start inserting data into ourmusicians_dbdatabase, so we need to log out as therootuser and log back into MySQL as the newly createdmusicfanuser:

    mysql> quit
    Bye
    $ mysql -u musicfan -p
    Enter password: CrimsonKing

    mysql>

    More Perl Articles
    More By Apress Publishing


       · This article is an excerpt from the book "Beginning Perl," published by Apress. We...
     

    Buy this book now. This article is excerpted from chapter 15 of the book Beginning Perl by James Lee (Apress; ISBN: 159059391X). Check it out today at your favorite bookstore. Buy this book now.

       

    PERL ARTICLES

    - Perl: Another Round with Hashes
    - Perl Hashes
    - Perl Lists: A Final Look at List::Util
    - Perl Lists: Utilizing List::Util
    - Perl Lists: The Split() Function
    - SQL and CGI with Perl and DBI
    - Perl Lists: More Functions and Operators
    - SELECT Queries and Perl
    - Perl Lists: More on Manipulation
    - Creating a Database with Perl and DBI
    - Perl: Sailing the List(less) Seas
    - Perl and DBI
    - Perl: Concatenating Text and More
    - Perl Text: Quoting Without Quote Marks
    - Perl: Releasing Your Inner Textuality

     
    Accelerating Trading Partner Performance
     
    Competing on Analytics
     
    Cost Effective Scaling with Virtualization and Coyote Point Systems
     
    Five Checkpoints to Implementing IP Telephony
     
    Hosted Email Security: Staying Ahead of New Threats
     




    © 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway