Perl PHP wrapper for Oracle Database ----------------------------------------------- Fri Aug 17 15:17:16 CDT 2007 - nocon Tested with: PHP 5.2.3 (cli) (built: Aug 16 2007 17:10:11) Copyright (c) 1997-2007 The PHP Group Zend Engine v2.2.0, Copyright (c) 1998-2007 Zend Technologies Description: This extension embeds Perl Interpreter into PHP. It allows execute Perl files, evaluate Perl code, access Perl variables and instantiate Perl objects. http://pecl.php.net/package/perl Using Perl Code from PHP http://devzone.zend.com/node/view/id/1712 Example Select For OracleDB ============================================================== eval(' use strict; use DBI; package OracleDB; sub new { my ($class) = shift; my ($dbh); my $self = {}; bless($self, $class); $ENV{"ORACLE_HOME"} = "/usr/local/oracle7"; my $server = "oracle.server.addr"; my $port = "12345"; my $sid = "oraclesid"; my $username = "DB_username"; my $password = "DB_passwd"; $dbh = DBI->connect( "dbi:Oracle:host=$server;sid=$sid;port=$port", $username, $password, { RaiseError => 1, AutoCommit => 0, PrintError => 1, LongReadLen => 1000000 } ) || die "$class: Database connection not made: $DBI::errstr"; $self->{database} = $dbh; return $self; } sub Select { my $self = shift; my $SqlStatement = shift; my $Database = $self->{database}; $SqlStatement = qq{$SqlStatement}; my $Sth = $Database->prepare($SqlStatement) || die "Error Preparing SQL Statment.\n"; if(!$Sth->execute()) { $Sth->finish(); $Database->disconnect(); return; } my $NumFields = $Sth->{NUM_OF_FIELDS}; my @data; my $RowNum = 0; my $x; while(@data = $Sth->fetchrow_array()) { for($x = 0; $x < $NumFields; $x++ ) { $self->{data}->[$RowNum]->{uc($Sth->{NAME}->[$x])} = "@data[$x]"; } $RowNum++; } $Sth->finish(); $Database->disconnect(); return; } '); $perl = new Perl("OracleDB"); $sql_statement = "select * from database where id in (6,90,35,278,91)"; try { $perl->Select($sql_statement); } catch (PerlException $exception) { echo "Perl error: " . $exception->getMessage() . " "; } print "
"; print_r($perl->data); print ""; ?>