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
9
votes
2 answers

Perl DBI fetchall_hashref

Consider the following table: mysql> select * from vCountryStatus; +-------------+------------+------+---------+--------+-----------------+ | CountryName | CountryISO | Code | Status | Symbol | CurrencyName …
emx
  • 1,295
  • 4
  • 17
  • 28
9
votes
1 answer

Perl warning: Use of uninitialized value in join or string

I'm getting: "Use of uninitialized value in join or string at ./test_script.pl line 69, line 91." The code creating this warning is here: # Write results of SQL execution to output file if ($@) { print "\n DB Error : ", $@; exit; } open(FH,…
Vas Vas
  • 91
  • 1
  • 1
  • 2
9
votes
5 answers

Is there an equivalent of PHP's mysql_real_escape_string() for Perl's DBI?

Could some tell me if there is a function which works the same as PHP's mysql_real_escape_string() for Perl from the DBI module?
Phil Jackson
  • 10,238
  • 23
  • 96
  • 130
9
votes
1 answer

perl DBI memory leak

I'm having some memory leak issues in a perl script that I'm running for extended periods of time, where the amount of memory that perl is taking up just continues to grow. Because of this, I am trying to use Devel::Leak to track down the leak. I…
srchulo
  • 5,143
  • 4
  • 43
  • 72
8
votes
2 answers

Perl DBI (MySQL) puts single quote instead of actual parameter in prepared statement

I'm trying to do a simple query as prepared statement but have no success. Here is the code: package sqltest; use DBI; DBI->trace(2); my $dbh = DBI->connect('dbi:mysql:database=test;host=***;port=3306','the_username', '****'); my $prep = 'SELECT…
deR_Ed
  • 528
  • 4
  • 15
8
votes
2 answers

How do I use spaces in parameters for DBI->connect?

I'm trying to connect with an SSL client key using DBI and DBD::Pg. use strict; use warnings 'all'; use DBI; my $dsn = "dbi:Pg:db=mydb;sslmode=require;host=localhost;" ."sslcert=C:\\path with\\spaces.crt;" ."sslkey=C:\\path…
RazerM
  • 5,128
  • 2
  • 25
  • 34
8
votes
4 answers

Reusing ?'s on a DBI prepare

Is there a way to reuse the ?'s used on a DBI prepare statement. Consider the following code: $sth=$dbh->prepare("INSERT INTO mytable(a,b,c) SELECT ?,B(?),C(?)"); $sth->execute($a,$a,$a); It would be very nice to instead use something like…
User1
  • 39,458
  • 69
  • 187
  • 265
8
votes
3 answers

How do I insert null fields with Perl's DBD::Pg?

I have a Perl script inserting data into Postgres according to a pipe delimited text file. Sometimes, a field is null (as expected). However, Perl makes this field into an empty string and the Postgres insert statement fails. Here's a snippet of…
User1
  • 39,458
  • 69
  • 187
  • 265
8
votes
2 answers

Manual transaction management in DBD::Pg

I'm having a hard time getting manual transactions to work as documented in DBD::Pg, or I'm simply misunderstanding said documentation. My understanding is that if I want to manually manage transactions, I should turn off…
Michael Soulier
  • 803
  • 1
  • 9
  • 20
8
votes
3 answers

Database fetchrow_array failed long truncated DBI attribute

i am pulling urls from my database with a perl script where i employ fetchrow_array to pull URL from the database which worked fine until i encountered a very long URL…
Marcus Lim
  • 567
  • 2
  • 5
  • 14
8
votes
5 answers

How can I show the query time in Perl, DBI?

I use Perl and DBI to manage my MySQL tables, querys, etc. How can I show the running time of a query? If I do a SELECT in the console, the result will be like this: +-----+-------------+ | id | name | +-----+-------------- | 1 | Jack …
netdjw
  • 5,419
  • 21
  • 88
  • 162
7
votes
3 answers

How do I get the number of affected rows when I use DBI's prepare/execute for non-select statement?

According to the DBI documentation, it seems I can only get the number of affected rows by the do method. $rows_affected = $dbh->do("UPDATE your_table SET foo = foo + 1"); How can I get the same result if I use prepare/execute?
new_perl
  • 7,345
  • 11
  • 42
  • 72
7
votes
3 answers

Dump prepared sql query from DBI statement in PERL

im using DBI in Perl to connect to my PostgreSQL Database. Everything is working fine but in my debugging (printing results etc.) iam not able to see if the query prepared by perls DBI module is really correct. I have something like…
NovumCoder
  • 4,349
  • 9
  • 43
  • 58
7
votes
4 answers

DBI: disconnect - question

Would you call parts of the disconnect-code as line-noise or would you leave it as it is? use DBI; my $dbh = DBI->connect ... ... ... END { $dbh->disconnect or die $DBI::errstr if $dbh; }
sid_com
  • 24,137
  • 26
  • 96
  • 187
7
votes
2 answers

Data Access Layer with Perl 6 and DBIish

I am trying to design a "data access layer" for my Perl 6 budgeting application. The goal is to have a user store various purchases in a SQLite database, and my application will generate various reports, informing the user of spending…
Jonathan Dewein
  • 984
  • 3
  • 16
  • 34
1 2
3
90 91