Solved

Installing the DBI Module

Posted on 2002-05-10
6
131 Views
Last Modified: 2013-12-25
How to?
0
Comment
Question by:lexxwern
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 3
  • 3
6 Comments
 
LVL 6

Accepted Solution

by:
andreif earned 100 total points
ID: 7002341
perl -MCPAN -e"install DBI"
0
 
LVL 12

Author Comment

by:lexxwern
ID: 7003069
ok i did install it, about.com, but anyway thanks to andreif for effort too.

anyway now a little change in the Q;

can im looking for a simple example, where tables are created and values written and read.

thanks...
0
 
LVL 6

Expert Comment

by:andreif
ID: 7003560
it depends on database, this example is for MySQL and queries can be not working with other databases. Anyway DBI module interface is the same.

use DBI;

# connect to DB
$dbh = DBI->connect ("DBI:mysql:database=$db",$user,$passwd) or die $DBI::errstr;

# create table
$sql = "
CREATE TABLE blocked_emails (
  email varchar(100)
)
";
$dbh->do($sql) or print $DBI::errstr;

# insert records
$sql = "insert into blocked_emails (email) values (?)";
$sth = $dbh->prepare($sql) or print $DBI::errstr;

$sth->execute("test@email.com") or print $DBI::errstr;
$sth->execute("test2@email.com") or print $DBI::errstr;

$sth->finish;


# select records
$sql = "select * from blocked_emails";
$sth = $dbh->prepare($sql) or print $DBI::errstr;
while ($record = $sth->fetchrow_hashref) {
  print "$$record{email}<br>";
}
$sth->finish;
0
What Is Transaction Monitoring and who needs it?

Synthetic Transaction Monitoring that you need for the day to day, which ensures your business website keeps running optimally, and that there is no downtime to impact your customer experience.

 
LVL 12

Author Comment

by:lexxwern
ID: 7004019
thanks andreif,

yes i use mysql, sorry for not letting you know earlier.

your examples were quite useful. a small doubt.


suppose a select returns more than one value, then how can it be written into arrays in one go.... or will i have to get data rowwise?
0
 
LVL 6

Expert Comment

by:andreif
ID: 7005331
Yes, you can use "fetchall_arrayref"

$tbl_ary_ref = $sth->fetchall_arrayref;

The fetchall_arrayref method can be used to fetch all the data to be returned from a prepared and executed statement handle. It returns a reference to an array that contains one reference per row.

This link can be useful for you:

http://www.mysql.com/doc/P/e/Perl_DBI_Class.html
0
 
LVL 12

Author Comment

by:lexxwern
ID: 7005334
Thankyou for the accurate help and the good link.
0

Featured Post

The Orion Papers

Are you interested in becoming an AWS Certified Solutions Architect?

Discover a new interactive way of training for the exam.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This tutorial will discuss the log-in process using WhizBase. In this article I assume you already know HTML. I will write the code using WhizBase Server Pages, so you need to know some basics in WBSP (you might look at some of my other articles abo…
In this tutorial I will show you how to provide a dynamic RTF document on your website generated with data from your database. For this tutorial you will need Microsoft Word or WordPad, WhizBase and Microsoft Access. In this tutorial I will show …
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question