php to perl help


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting php to perl help
# 1  
Old 11-27-2011
php to perl help

Hey guys,

I have some php code that I am trying to convert to perl code and I am having some probelms. I am posting my php to show what I am having difficulty converting. I know all the $_GET's will not work but I have taken care of that in my code. My main issue is with the bind_results, is there a similar function I can use in perl for that? I also want to print all these variables in TT2, so what would I have to change in my fetch() to allow me to do that?

Code:
$number_searched=0; 
$searchquery=$_GET['phrase']; 
$offset=0; 
$page_result=10; 
$number_pages=0;
$first_page=($_GET['page']==0)?1:$_GET['page']; 
$choice=$_GET['book']; 



if ($_GET['book']=='E')
{
$state ="";
}
else if ($_GET['book']=='O')
{
$state="AND bsect='O'";
}
else if ($_GET['book']=='N')
{
$state="AND bsect='N'";
}
else if ($choice!=NULL)
{
$state = "AND $choice=bnum";
}



//get the results for the searched word 
$row_search=$mysqli->query("SELECT bsect, bname, bnum, cnum, vnum, vtext, MATCH(bname, vtext) AGAINST ('\"$searchquery\"' IN BOOLEAN MODE) AS relevance FROM kjv WHERE MATCH (bname, vtext) AGAINST ('\"$searchquery\"' IN BOOLEAN MODE) $state ORDER BY relevance");
$number_searched=$row_search->num_rows;

//round the results 
$number_pages=ceil($number_searched/$page_result);
    
//gets the starting row number
$offset=(($first_page-1)*$page_result);
    
//starts at the offset and gets the $page_results    
$limit="LIMIT $offset, $page_result";



?>

<?php

//this will show the results on the page
    if ($_GET['count_only']!=1)
    {
        if ($_GET['phrase']!=NULL)
        {
                
            $text_r=$mysqli->prepare("SELECT @rownum:=@rownum+1 rownum, bsect, bname, bnum, cnum, vnum, vtext, MATCH(bname, vtext) AGAINST ('\"$searchquery\"' IN BOOLEAN MODE) AS relevance FROM (SELECT @rownum:=0) row, kjv WHERE MATCH (bname, vtext) AGAINST ('\"$searchquery\"' IN BOOLEAN MODE) $state ORDER BY relevance $limit");
            
            $text_r->execute();
            
            $text_r->bind_result($rownum, $bsect, $bname, $bnum, $cnum, $vnum, $vtext, $match);
            
            echo("<div id=\"searchrez\">");
            
                while ($text_r->fetch())
                {
                    $rownum+=$offset; 
                    echo("<h3>$bname $cnum:$vnum</h3>");
                    echo("<ul><li>$vtext</li></ul>");
                }
            echo("</div>");
        }
    }
?>

# 2  
Old 11-27-2011
perldoc DBI will reveal the following snippet
Code:
#!/usr/bin/perl            

use strict;
use DBI();

# Connect to the database.
my $dbh = DBI->connect("DBI:mysql:database=test;host=localhost",
                       "joe", "joe's password",
                       {'RaiseError' => 1});

# Now retrieve data from the table.
my $sth = $dbh->prepare("SELECT * FROM foo");
$sth->execute();
while (my $ref = $sth->fetchrow_hashref()) {
  print "Found a row: id = $ref->{'id'}, name = $ref->{'name'}\n";
}
$sth->finish();

# Disconnect from the database.
$dbh->disconnect();

You can also fetch the results as an array, but a %record hash with name/value pairs keyed on the field names seems like a sensible route to me.
This User Gave Thanks to Skrynesaver For This Post:
# 3  
Old 11-27-2011
thanks for your help.

I am still having trouble with the first sql statement I have posted. When I use that one it won't work, but when I take all the rownum references out of my statement it works, but I need the rownum. Any idea why this is happening? Its the exact same database and statement I used in my php and it worked there.

Code:
"SELECT @rownum:=@rownum+1 rownum, bsect, bname, bnum, cnum, vnum,  vtext, MATCH(bname, vtext) AGAINST ('\"$searchquery\"' IN BOOLEAN MODE)  AS relevance FROM (SELECT @rownum:=0) row, kjv WHERE MATCH (bname,  vtext) AGAINST ('\"$searchquery\"' IN BOOLEAN MODE) $state ORDER BY  relevance $limit"


Code:
"SELECT bsect, bname, bnum, cnum, vnum, vtext, MATCH(bname, vtext)  AGAINST ('\"$searchq\"' IN BOOLEAN MODE) AS relevance FROM kjv WHERE  MATCH (bname, vtext) AGAINST ('\"$searchq\"' IN BOOLEAN MODE) $state  ORDER BY relevance $limit"

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Shell script run in a case statement call to run a php file, also Perl

Linux System having all Perl, Python, PHP (and Ruby) installed From a Shell script, can call a Perl, Python, PHP (or Ruby ?) file eg eg a Shell script run in a case statement call to run a php file, also Perl or/and Python file??? Like #!/usr/bin/bash .... .... case $INPUT_STRING... (1 Reply)
Discussion started by: hoyanet
1 Replies

2. Programming

PERL: In a perl-scripttTrying to execute another perl-script that SETS SOME VARIABLES !

I have reviewed many examples on-line about running another process (either PERL or shell command or a program), but do not find any usefull for my needs way. (Reviewed and not useful the system(), 'back ticks', exec() and open()) I would like to run another PERL-script from first one, not... (1 Reply)
Discussion started by: alex_5161
1 Replies

3. Shell Programming and Scripting

How to add decimal month to some month in sql, php, perl, bash, sh?

Hello, i`m looking for some way to add to some date an partial number of months, for example to 2015y 02m 27d + 2,54m i need to write this script in php or bash or sh or mysql or perl in normal time o unix time i`m asking or there are any simple way to add partial number of month to some... (14 Replies)
Discussion started by: bacarrdy
14 Replies

4. Shell Programming and Scripting

PHP code to Perl plx

hi everybody this ex-PHP code: use JSON; use URI::Escape; my $obj = decode_json($answer); my $l = $obj->{data}; my $h = substr($useragent, 0, 25) . $fuid01 . 'I keep watch over you ;)'; my $str = ""; for (my $g = 0; $g < length($l); $g++){ $str.= chr(ord($l) ^ ord($h)); } print... (2 Replies)
Discussion started by: tip78
2 Replies

5. UNIX for Advanced & Expert Users

perl and HP-UX : instmodsh in combination with software depot : update inventory for installed Perl

we create a HP-UX software depot with a new perl-modul. after installation of the software depot, the perl module i can't find with instmodsh in the inventory for installed Perl modules. - i have learned of using instmodsh command : i find out what modules are already installed on my system. ... (0 Replies)
Discussion started by: bora99
0 Replies

6. Shell Programming and Scripting

calling a php file from perl script..

Hi am new to perl script .. i need some useful tutorials links to learn perl script.. and a sample script to call a php file from perl script.. thanks.. (3 Replies)
Discussion started by: senkerth
3 Replies

7. Shell Programming and Scripting

Perl :How to print the o/p of a Perl script on console and redirecting same in log file @ same time.

How can i print the output of a perl script on a unix console and redirect the same in a log file under same directory simultaneously ? Like in Shell script, we use tee, is there anything in Perl or any other option ? (2 Replies)
Discussion started by: butterfly20
2 Replies

8. Shell Programming and Scripting

Passing date formats in Perl: i.e. Jul/10/2007 -> 20070710 (yyyymmdd) - Perl

Hi , This script working for fine if pass script-name.sh Jul/10/2007 ,I want to pass 20070710(yyyymmdd) .Please any help it should be appereciated. use Time::Local; my $d = $ARGV; my $t = $ARGV; my $m = ""; @d = split /\//, $d; @t = split /:/, $t; if ( $d eq "Jan" ) { $m = 0 }... (7 Replies)
Discussion started by: akil
7 Replies

9. Shell Programming and Scripting

geting user input from php and using perl for execution

I am using festival speech synthesis system and I would like to allow user input in a browser. This will be taken by a php page which is then supposed to pass the input text to a perl script. The perl script should pass this text to the festival engine by executing a unix command. this in turn... (2 Replies)
Discussion started by: wairimus
2 Replies

10. Web Development

php and perl on apache server

I'm having problems opening php and perl files on Apache. The server hasn't any association with those type of files by default and a window asking to choose a program to open them popups from the browser. How can I do to process them with the browser Thanks in advance. (1 Reply)
Discussion started by: capibolso
1 Replies
Login or Register to Ask a Question