# info > DBI::PurePerl

---
type: CommandReference
command: DBI::PurePerl
mode: perldoc
section: 3pm
source: perldoc
---

## Quick Reference

- `BEGIN { $ENV{DBI_PUREPERL} = 2 }` — Force PurePerl before loading DBI
- `use DBI` — Load DBI module (uses PurePerl if env set)
- `DBI->connect($dsn, $user, $pass)` — Connect to database (same as standard DBI)
- `$dbh->prepare($statement)` — Prepare a statement (slower than standard DBI)
- `$dbh->do($statement)` — Execute a statement directly
- `$sth->execute()` — Execute a prepared statement
- `$sth->fetchrow_array()` — Fetch next row as array
- `$sth->finish()` — Finish statement handle

## Name

`DBI::PurePerl` — a DBI emulation using pure perl (no C/XS compilation required)

## Synopsis

perl
BEGIN { $ENV{DBI_PUREPERL} = 2 }
use DBI;
## Description

This is a pure perl emulation of the DBI internals. It is slower than the standard compiled DBI, but allows using pure-perl DBD drivers without needing any compiled C code. Use it when you cannot install the compiled version of standard DBI.

## Options

### Environment variable `DBI_PUREPERL`

- `DBI_PUREPERL = 0` (default) — Always use compiled DBI; die if not properly compiled and installed.
- `DBI_PUREPERL = 1` — Use compiled DBI if available; otherwise use PurePerl.
- `DBI_PUREPERL = 2` — Always use PurePerl.

Set it in the shell or in a script with `BEGIN { $ENV{DBI_PUREPERL}=2 }` before `use DBI`.

### Unsupported or limited attributes

- `ActiveKids`, `InactiveDestroy`, `AutoInactiveDestroy`, `Kids`, `Taint`, `TaintIn`, `TaintOut` — Not supported or have limited functionality.

### Other limitations

- **Tracing** — `trace()` method only works if `DBI_TRACE` environment variable is set (set to 0 for handle-specific tracing).
- **Parameter checking** — No parameter count checking on method calls.
- **`preparse()`** — Not supported.
- **`hash($string,1)`** — Requires `Math::BigInt` >= 1.56.
- **`can()`** — No special behavior.
- **`DBD::Proxy`** — Not fully supported.
- **Speed** — Slower than compiled DBI (e.g., ~2800 vs ~4550 handles per second in a benchmark).

## Examples

### Manual installation (when DBI itself cannot be installed)

perl
cp DBI.pm      /usr/jdoe/mylibs/.
cp PurePerl.pm /usr/jdoe/mylibs/DBI/.
Then add to scripts:

perl
BEGIN {
  $ENV{DBI_PUREPERL} = 1;      # or =2
  unshift @INC, '/usr/jdoe/mylibs';
}
### Benchmark (from DBI source test.pl)

perl
my $null_dbh = DBI->connect('dbi:NullP:','','');
my $i = 10_000;
$null_dbh->prepare('') while $i--;
## See Also

- [DBI](https://perldoc.perl.org/DBI)
- [DBD::CSV](https://perldoc.perl.org/DBD::CSV)
- [DBD::AnyData](https://perldoc.perl.org/DBD::AnyData)
- [DBD::XBase](https://perldoc.perl.org/DBD::XBase)
- [DBD::Sprite](https://perldoc.perl.org/DBD::Sprite)
- [DBD::mysqlPP](https://perldoc.perl.org/DBD::mysqlPP)
- [Math::BigInt](https://perldoc.perl.org/Math::BigInt)