SitePoint Sponsor

User Tag List

Results 1 to 7 of 7

Thread: can somebody php into perl?

  1. #1
    SitePoint Enthusiast
    Join Date
    Jul 2002
    Location
    Switzerland
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    can somebody translate this script from php into perl?

    I need urgently this short php script translated into Perl. I only know php and have no idea of perl, would be great if somebody could do it for me, thanks!!

    PHP Code:

    <?
    //---------start script
    $username="xxxxxx";
    $password="yyyyyyy";
    $database="zzzzzzz";
    mysql_connect(localhost,$username,$password);
    mysql_select_db($database) or die( "Unable to select database");

    $sql "SELECT count(*) FROM jobs WHERE approve=0";

    $count mysql_result($result0);

    print 
    $count

    //---------end scipt--------
    ?>
    Last edited by raffael3d; Oct 17, 2002 at 15:45.

  2. #2
    SitePoint Wizard samsm's Avatar
    Join Date
    Nov 2001
    Location
    Atlanta, GA, USA
    Posts
    5,011
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This is the article for you!

    Access your MySQL Database with Perl
    http://www.webmasterbase.com/article/54

    Start with that, what remains will be easy as pie.
    Using your unpaid time to add free content to SitePoint Pty Ltd's portfolio?

  3. #3
    SitePoint Enthusiast
    Join Date
    Jul 2002
    Location
    Switzerland
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanks!
    I tried this:

    # connect
    my $dbh = DBI->connect("dbi:mysql:XXXXX:localhost:YYYYY", "user", "pass");

    # prepare the query
    my $sth = $dbh->prepare("SELECT count(*) FROM jobs WHERE approve=0");

    # execute the query
    $sth->execute();


    $count = $sth($result, 0);

    print $count;




    but it doesn't work. any tips?

  4. #4
    SitePoint Wizard
    Join Date
    Jul 2001
    Location
    The Netherlands
    Posts
    2,617
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I don't see a shebang line in the code you posted, is it there in the original code?

  5. #5
    SitePoint Member
    Join Date
    Oct 2002
    Location
    London, UK
    Posts
    6
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also, try adding an 'or die' clause at the end of the statements, as you can then catch any errors that might be happening:

    use DBI;
    my $dbh = DBI->connect("dbi:mysql:XXXXX:localhost:YYYYY", "user", "pass") or die $DBI::errstr;

    # prepare the query
    my $sth = $dbh->prepare("SELECT count(*) FROM jobs WHERE approve=0") or die $DBI::errstr;

    # execute the query
    $sth->execute() or die $DBI::errstr;

    etc...
    Luke Dawson

  6. #6
    SitePoint Enthusiast
    Join Date
    Jul 2002
    Location
    Switzerland
    Posts
    45
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the original script is here . I tried to modify it so taht it outputs the amount of entries in the database. Sorry I only know PHP, not too much Perl.


    use DBI;
    use CGI;

    print CGI::header();

    print "<h1>Subscribers</h1>";

    # connect
    my $dbh = DBI->connect("dbi:mysql:shoes:localhost:3306", "user", "pass");

    # prepare the query
    my $sth = $dbh->prepare("select username, emailaddr from subscribers");

    # execute the query
    $sth->execute();

    while(my ($username, $email) = $sth->fetchrow_array()) {
    print "$username: $email<br>\n";
    }


    from http://www.webmasterbase.com/article/545/5

  7. #7
    SitePoint Wizard
    Join Date
    Jul 2001
    Location
    The Netherlands
    Posts
    2,617
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need to add a shebang line to your code in order for it to be parsed through a Perl interpreter.
    It looks like this:

    Code:
    #! /usr/local/bin/perl
    You have to modify it to the location of the Perl folder on your system.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •