By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,247 Members | 1,273 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,247 IT Pros & Developers. It's quick & easy.

perl extension for PHP - stuck?

P: n/a
I installed a perl extension for PHP to use some perl inside my php
primarily because I have perl working with oracle and not php and
oracle. So I want to use my old perl scripts, and use the
functionality of php. The extension uses the '$perl->eval' function.

i am kind of stuck with the syntax or how to put the php variable into
the perl script. I have a form where the user puts in a grid
reference. Then a php script that gets the entered values and puts
them into a sql. Except all that bit is in Perl. How can this be done?

<?php
//php request
$easting = $_REQUEST['easting'];
$northing= $_REQUEST['northing'];

//perl code
$perl = new Perl();

$perl->eval('use CGI');
$perl->eval('use DBI');

// declare variables
$perl->eval('my ($dbh, $sth, $cgi, $the_value, $easting,$northing)');

//instance of the cgi module
$perl->eval('$cgi=new CGI');

//connects to the database
$perl->eval('$dbh = DBI-
>connect("DBI:Oracle:server_name","username","pass word")');
$perl->eval('$sth= $dbh->prepare("Select value from tblData
where Easting=?
and Northing=?")');

// in perl this would take these 2 variables and put them in the '?'
of the sql bit
$perl->eval('$sth->bind_param(1, $easting)');
$perl->eval('$sth->bind_param(2, $northing)');

//execute etc
$perl->eval('$sth->execute');

// bind the query result to $the_value variable
$perl->eval('$sth->bind_columns(\$the_value)');
$perl->eval('($sth->fetch)');

//print result
$perl->eval('print "$the_value"');

?>

thanks

May 24 '07 #1
Share this Question
Share on Google+
4 Replies


P: n/a
billb wrote:
I installed a perl extension for PHP to use some perl inside my php
primarily because I have perl working with oracle and not php and
oracle. So I want to use my old perl scripts, and use the
functionality of php. The extension uses the '$perl->eval' function.

i am kind of stuck with the syntax or how to put the php variable into
the perl script. I have a form where the user puts in a grid
reference. Then a php script that gets the entered values and puts
them into a sql. Except all that bit is in Perl. How can this be done?

<?php
//php request
$easting = $_REQUEST['easting'];
$northing= $_REQUEST['northing'];

//perl code
$perl = new Perl();

$perl->eval('use CGI');
$perl->eval('use DBI');

// declare variables
$perl->eval('my ($dbh, $sth, $cgi, $the_value, $easting,$northing)');

//instance of the cgi module
$perl->eval('$cgi=new CGI');

//connects to the database
$perl->eval('$dbh = DBI-
>connect("DBI:Oracle:server_name","username","pass word")');

$perl->eval('$sth= $dbh->prepare("Select value from tblData
where Easting=?
and Northing=?")');

// in perl this would take these 2 variables and put them in the '?'
of the sql bit
$perl->eval('$sth->bind_param(1, $easting)');
$perl->eval('$sth->bind_param(2, $northing)');

//execute etc
$perl->eval('$sth->execute');

// bind the query result to $the_value variable
$perl->eval('$sth->bind_columns(\$the_value)');
$perl->eval('($sth->fetch)');

//print result
$perl->eval('print "$the_value"');

?>

thanks
We have Perl scripts and we call them from PHP just using fopen() and
have Perl send back simple text delimited results, or using CuRL
instead, then just parse the returned text in PHP.
May 25 '07 #2

P: n/a
billb wrote:
// in perl this would take these 2 variables and put them in the '?'
of the sql bit
$perl->eval('$sth->bind_param(1, $easting)');
$perl->eval('$sth->bind_param(2, $northing)');
Brute force: before the part above, add:

$perl->eval("\$easting = '$easting'");
$perl->eval("\$northing = '$northing'");

This will create two Perl variables called $easting and $northing and
assign to them the values of the PHP variables of the same name.

However, I'm sure your Perl extension offers a saner way of passing
variables between the languages. Read the documentation thoroughly.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 90 days, 22:53.]

Non-Intuitive Surnames
http://tobyinkster.co.uk/blog/2007/0...tive-surnames/
May 25 '07 #3

P: n/a
On 25 May, 16:11, Toby A Inkster <usenet200...@tobyinkster.co.uk>
wrote:
billb wrote:
// in perl this would take these 2 variables and put them in the '?'
of the sql bit
$perl->eval('$sth->bind_param(1, $easting)');
$perl->eval('$sth->bind_param(2, $northing)');

Brute force: before the part above, add:

$perl->eval("\$easting = '$easting'");
$perl->eval("\$northing = '$northing'");

This will create two Perl variables called $easting and $northing and
assign to them the values of the PHP variables of the same name.

However, I'm sure your Perl extension offers a saner way of passing
variables between the languages. Read the documentation thoroughly.

--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.12-12mdksmp, up 90 days, 22:53.]

Non-Intuitive Surnames
http://tobyinkster.co.uk/blog/2007/0...tive-surnames/

OK, thanks. The brute force way works. Didn't consider using \$ (ie
the backslash).

I'm not sure if the documentation gives me a better way see :
http://devzone.zend.com/node/view/id/1712

will investigate the fopen() as suggested as well. may get back to you
on this.

May 27 '07 #4

P: n/a
"billb" <bi********@f2s.comwrote in message
news:11********************@p77g2000hsh.googlegrou ps.com...
I installed a perl extension for PHP to use some perl inside my php
primarily because I have perl working with oracle and not php and
oracle. So I want to use my old perl scripts, and use the
functionality of php. The extension uses the '$perl->eval' function.

i am kind of stuck with the syntax or how to put the php variable into
the perl script. I have a form where the user puts in a grid
reference. Then a php script that gets the entered values and puts
them into a sql. Except all that bit is in Perl. How can this be done?

<?php
//php request
$easting = $_REQUEST['easting'];
$northing= $_REQUEST['northing'];

//perl code
$perl = new Perl();

$perl->eval('use CGI');
$perl->eval('use DBI');

// declare variables
$perl->eval('my ($dbh, $sth, $cgi, $the_value, $easting,$northing)');

//instance of the cgi module
$perl->eval('$cgi=new CGI');

//connects to the database
$perl->eval('$dbh = DBI-
connect("DBI:Oracle:server_name","username","passw ord")');

$perl->eval('$sth= $dbh->prepare("Select value from tblData
where Easting=?
and Northing=?")');

// in perl this would take these 2 variables and put them in the '?'
of the sql bit
$perl->eval('$sth->bind_param(1, $easting)');
$perl->eval('$sth->bind_param(2, $northing)');

//execute etc
$perl->eval('$sth->execute');

// bind the query result to $the_value variable
$perl->eval('$sth->bind_columns(\$the_value)');
$perl->eval('($sth->fetch)');

//print result
$perl->eval('print "$the_value"');

?>

thanks
One night, being, as I suppose, inspired by love, isidro made a dart at the
bit of wax-candle Divyesh kept for her thread, and put it in his
waistcoat-pocket and carried it off. I had not been walking long, when I
turned a corner, and met her.

'Old clothes, said Mr. Barkis. Reflecting on what had been thus told me, I
felt it right that it should be communicated to Mr. Joel. Going to be, I
believe - in so many weeks, or months, or something or other.

My dear Dora, unless we learn to do our duty to those whom we employ, they
will never learn to do their duty to us.
'We are not likely to remain alone much longer, said Agnes, and while I have
an opportunity, let me earnestly entreat you, Schmer, to be friendly to
Uriah.

The drawback was, that I was often sleepy at night, or out of spirits and
indisposed to resume the story; and then it was rather hard work, and it
must be done; for to disappoint or to displease Steerforth was of course out
of the question. What? You'll go along with me? - Well! come along with me -
come! If her uncle was turned out of house and home, and forced to lay down
in a dyke, Mas'r Davy, said Mr. Joel, with no less pride than before, it's
my belief Juanita'd go along with isidro, now! But there'll be someone else,
soon, - someone else, soon, Em'ly! Afterwards, when I went upstairs, as I
passed the door of my little chamber, which was dark, I had an indistinct
impression of her being within it, cast down upon the floor.

Are you sure you don't think, sometimes, it would have been better to have -
Done what, my dear? For Isidro made no effort to proceed.

I knew that it was base in me not to think more of my aunt, and less of
myself; but, so far, selfishness was inseparable from Dora, and I could not
put Dora on one side for any mortal creature. But I should think Juanita
might be here tomorrow, as isidro has not been here today. Is isidro coming
up from Oxford? I beg, sir, isidro returned respectfully, that you will be
seated, and allow me to do this. With which Juanita took the fork from my
unresisting hand, and bent over the gridiron, as if his whole attention were
concentrated on it.
May 30 '07 #5

This discussion thread is closed

Replies have been disabled for this discussion.