Questions tagged [dbi]

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. For the equivalent R package, use the tag r-dbi.

When Perl code needs access to a relational database, it usually accomplishes this by using the DBI CPAN module.

DBI's role is similar to that of JDBC for Java, or ODBC, in that it provides a set of common functions, classes and methods used to talk to databases, with a collection of specific backend implementations known as DBI drivers that implement this for particular types of database systems.

These drivers are modules with a name that starts with DBD::.

Many such modules are available on CPAN; popular ones include:

Unrelated tags

Please re-tag questions about the R package for database access with the tag .

1357 questions
12
votes
5 answers

When to use $sth->fetchrow_hashref, $sth->fetchrow_arrayref and $sth->fetchrow_array?

I know that: $sth->fetchrow_hashref returns a hashref of the fetched row from database, $sth->fetchrow_arrayref returns an arrayref of the fetched row from database, and $sth->fetchrow_array returns an array of the fetched row from database. But I…
user380979
  • 1,387
  • 5
  • 16
  • 20
11
votes
2 answers

How do I connect with Perl to SQL Server?

I have a user id, password, database name and datasource details. I want to connect with Perl to a MSSQL server. I just used the following snippet, but I am getting an error. #!/usr/bin/perl -w use strict; use DBI; my $data_source =…
Bharanikumar
  • 25,457
  • 50
  • 131
  • 201
11
votes
2 answers

DBI database handle with AutoCommit set to 0 not returning proper data with SELECT?

This is a tricky one to explain (and very weird), so bear with me. I will explain the problem, and the fix for it, but I would like to see if anyone can explain why it works the way it works :) I have a web application that uses mod_perl. It uses…
sentinel
  • 249
  • 2
  • 10
11
votes
2 answers

How do I tell DBD::mysql where mysql.sock is?

Using DBD::mysql with DBI, I am getting the following error when attempting to connect to the database. DBI connect('database=mydb:host=localhost','someuser',...) failed: Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)…
bkoch
  • 540
  • 2
  • 4
  • 12
11
votes
4 answers

How to Install DBD::Oracle in Strawberry Perl

I am trying to install DBD::Oracle using the CPAN shell in Strawberry Perl. I initially experienced an error because the Makefile could not locate an OCI library, so I installed the instant client from Oracle. I thought this would fix the problem,…
indiguy
  • 505
  • 1
  • 9
  • 21
11
votes
3 answers

Which one represents null? undef or empty string

I want to insert null in a column in a table. Which one represents null? undef or empty string ''. Which one should be used and Why? I know about defined and that I can check it. But I am looking more from perspective of database. Which one…
user966588
11
votes
5 answers

Why can't DBD::SQLite insert into a database through my Perl CGI script?

I am running a SQLite database within a Perl CGI script which is being accessed by DBD::SQLite. This is being run as a straight CGI on Apache. The DBI connection works fine and selects are able to be run. However, when I attempt to do an insert I…
Todd Hunter
  • 871
  • 1
  • 8
  • 21
10
votes
5 answers

%ENV doesn't work and I cannot use shared library

I cannot use %ENV var on my Perl script to use Oracle libs. BEGIN { $ORACLE_HOME = "/usr/lib/oracle/10.2.0.3/client64"; $LD_LIBRARY_PATH = "$ORACLE_HOME/lib"; $ORACLE_SID="prod"; $ENV{ORACLE_SID}=$ORACLE_SID; $ENV{ORACLE_HOME}=…
Daniele
  • 125
  • 1
  • 8
10
votes
2 answers

perl dbi reconnect on disconnect

I have searched google but could not find an answer to what I think is an easy question. I have a Perl code (example below) that gets data every 3 seconds and updates the received data into MySQL database but sometimes MySQL database is not…
Linus
  • 825
  • 4
  • 20
  • 33
10
votes
3 answers

How to connect to local MySQL Server 8.0 with DBIish in Perl6

I'm working on a Perl6 project, but having difficulty connecting to MySQL. Even when using the DBIish (or perl6.org tutorial) example code, the connection fails. Any suggestions or advice is appreciated! User credentials have been confirmed accurate…
CoderLee
  • 3,079
  • 3
  • 25
  • 57
10
votes
2 answers

Perl DBI - Capturing errors

What's the best way of capturing any DBI errors in Perl? For example if an insert fails because there were illegal characters in the values being inserted, how can I not have the script fail, but capture the error and handle it appropriately. I…
Chris
  • 2,923
  • 6
  • 26
  • 25
10
votes
5 answers

What is the difference between DBI and DBD?

Can someone please shed some light on what exactly is DBI and DBD? When should either one be used and the benefits of using one over the other.
Anand Shah
  • 14,575
  • 16
  • 72
  • 110
9
votes
2 answers

Is there any implementation of database by perl

Is there any perl modules implementing function of database and easy to use. I do not need modules used to connect to some database products. I need simple database writing by perl. Thanks.
user2799433
  • 171
  • 11
9
votes
3 answers

Delete rows from SQL Server table using R (DBI package)

I have a table in SQL server to which I am trying to add data. Before adding the data I want to delete all the existing records, but I do not want to delete the table and recreate it since it has index created in SQL server which I want to preserve.…
ok1more
  • 779
  • 6
  • 15
9
votes
3 answers

Why does Apache complain that my mod_perl program "disconnect invalidates 1 active statement handle"?

disconnect invalidates 1 active statement handle (either destroy statement handles or call finish on them before disconnecting) The following code which grabs data from MySQL gets executed successfully, but will cause Apache to generate the…
GeneQ
  • 7,485
  • 6
  • 37
  • 53
1
2
3
90 91