perl extension for PHP - stuck?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • billb

    perl extension for PHP - stuck?

    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,$north ing)');

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

    //connects to the database
    $perl->eval('$dbh = DBI-
    >connect("DBI:O racle:server_na me","username", "password") ');
    $perl->eval('$sth= $dbh->prepare("Selec t 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

  • Tyno Gendo

    #2
    Re: perl extension for PHP - stuck?

    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,$north ing)');
    >
    //instance of the cgi module
    $perl->eval('$cgi=n ew CGI');
    >
    //connects to the database
    $perl->eval('$dbh = DBI-
    >connect("DBI:O racle:server_na me","username", "password") ');
    >
    $perl->eval('$sth= $dbh->prepare("Selec t 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.

    Comment

    • Toby A Inkster

      #3
      Re: perl extension for PHP - stuck?

      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("\$eastin g = '$easting'");
      $perl->eval("\$northi ng = '$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

      Comment

      • billb

        #4
        Re: perl extension for PHP - stuck?

        On 25 May, 16:11, Toby A Inkster <usenet200...@t obyinkster.co.u k>
        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("\$eastin g = '$easting'");
        $perl->eval("\$northi ng = '$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 :


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

        Comment

        • Varun

          #5
          Re: perl extension for PHP - stuck?

          "billb" <billbealey@f2s .comwrote in message
          news:1180015412 .218541.3980@p7 7g2000hsh.googl egroups.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,$north ing)');
          >
          //instance of the cgi module
          $perl->eval('$cgi=n ew CGI');
          >
          //connects to the database
          $perl->eval('$dbh = DBI-
          connect("DBI:Or acle:server_nam e","username"," password")');
          >
          $perl->eval('$sth= $dbh->prepare("Selec t 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.


          Comment

          Working...