iNET Interactive - Online Advertising Agency
          
   Home    Authors    About    Login    Contact Us
   Search:   
Advanced Search     
  Articles

  ASP (26)
  ASP.NET (19)
  C and C++ (4)
  CFML (2)
  CGI and Perl (16)
  Flash (2)
  Java (7)
  JavaScript (28)
  PHP (92)
  MySQL (13)
  MSSQL (3)
  HTML (34)
  SEO (9)
  Visual Basic (12)
  CSS (13)
  SSI (5)
  XML (12)
  C# (14)

  Developer News

May 15, 2008
Reader Question - Would you host your client's work on your website?
About
 
May 15, 2008
How to Create an Ajax Autocomplete Text Field: Part 6
WebReference.com
 
May 14, 2008
Poll: Are the browser safe colors still needed?
About
 
May 14, 2008
Google Doctype launched
About
 
May 14, 2008
Web Editor Reviews - 6 New Reviews
About
 
May 14, 2008
Build Beautiful Buttons in Photoshop, Part I
SitePoint
 
Courtesy of moreover.com
 
Want to receive new articles via e-mail? Click here!
/Home /CGI and Perl

Perl And MySQL; Using DBI; Connections 

  Views:    11400
  Votes:    2
by Gyan Kapur 11/27/03 Rating: 

Synopsis:

Perl abstracts databases using DBI, its database independent interface. Writing code using DBI is simple, for a programmer who has used Perl before, but for novices it can be a scary experience. This tutorial series aims at making the transition from flatfiles, or any other type of database to DBI a bit simpler. This article will focus on how to connect to a MySQL database, what it means, and what one can do from there.
Pages: firstback2 3 forwardlast
The Article

Tim Bunce, the lead developer of DBI.pm, asserts 'The DBI is a database access module for the Perl programming language. It defines a set of methods, variables, and conventions that provide a consistent database interface, independent of the actual database being used. [..] The DBI is a layer of 'glue' between an application and one or more database driver modules. It is the driver modules which do most of the real work. The DBI provides a standard interface and framework for the drivers to operate within.' (http://search.cpan.org/~timb/DBI-1.38/DBI.pm)

However, DBI attempts to make it simple for programmers by creating almost seamless integration with drivers. It's only when databases have different specifications that one actually has to take note of which database they're using.  The most notable differences are between transactional databases, and specific functions that may be linked to specific queries, such as fetching the index of an automatically incrementing database.  This tutorial will cover the basics of databases, assuming that you will have access to a server with Perl, MySQL, and DBI.

Opening The Connection

 use DBI;
  $dsn      = 'dbi:mysql:dbname=NameOfDatabase';
  $user     = 'mysqlusername';
  $password = 'mysqlpassword';
  $dbh      = DBI->connect($dsn, $user, $password,
                       { RaiseError => 1, AutoCommit => 0 });

What exactly this code mean? Obviously, you're connecting to the database, but what are these variables standing for?

Pages: firstback2 3 forwardlast

Similar/related articles:


 
  Sponsors