How to include a .pl (PERL) file in PHP

I have two pages, one in php (index.php) and the other in Perl (dbcon.pl).

Basically, I want only the user interface to be displayed in my php file, and all data operations should be performed in the Perl file.

I tried in index.pl

<?php include("dbcon.pl");?>
<html>
<br/>PHP</br>
</html>

and dbcon.pl has

#!/usr/bin/perl
use strict;
use warnings;
use DBI;

use CGI::Simple;
my $cgi = CGI::Simple->new;
my $dsn = sprintf('DBI:mysql:database=%s;host=%s','dbname','localhost');

my $dbh = DBI->connect($dsn,root =>'',{AutoCommit => 0,RaisError=> 0});


my $sql= "SELECT * FROM products";
my $sth =$dbh->prepare($sql);
$sth->execute   or die "SQL Error: $DBI::errstr\n";
while (my @row = $sth->fetchrow_array){
print $cgi->header, <<html;
<div>&nbsp;@row[0]&nbsp;@row[1]&nbsp;@row[2]&nbsp;@row[3]&nbsp;@row[4]</div>
html
}

but when I run index.php in the browser, it prints all the code in the dbcon.pl file instead of executing it

How to solve this problem?

note: i run this on windows environment

is there any other way to do this?

-5
source share
4 answers

May I ask what is the problem? I don't see anything special in Perl code, so you also:

a) Do not know how to access your database from PHP (i.e. you do not know PHP) or

b) , Perl (.. Perl)

c) , , Perl DBI, PHP.

, Perl PHP. PHP/DB.

- , : Perl script ( ).

, , , -, Perl ( , ).

, - - , ( ) Perl "", - XML-RPC .

exec() - .

+5

, , . perl script PHP, , :

<?php echo exec('perl dbcon.pl'); ?>

, . PHP.

+2

Perl PECL Perl PHP.

P.S. , ​​ Template Toolkit Perl. Perl .

+2

If you use Catalyst , you can Catalyst :: View :: PHP. I suspect this will give you more information on how to use php as your template system. He also mentions PHP :: Interpreter

0
source

All Articles