Perl Mania

Would you like to react to this message? Create an account in a few clicks or log in to continue.

Perl - Practical Extraction and Report Language. Ask questions and Suggest Answers about perl programming, syntax, variables, scoping, constructs, operators and functions, files, I/O, regular expressions, regex, subroutines, perl mod


3 posters

    perl beginner

    avatar
    Anitha
    Newbie
    Newbie


    Posts : 6
    Join date : 2008-12-02

    perl beginner Empty perl beginner

    Post  Anitha Wed Dec 10, 2008 5:28 am

    hi,
    Iam very new to perl.
    Here iam trying to connect to Database and trying to fetch the node names of customer by using sql. i am expecting that my query needs to be prepared and executed and returns the reuslts.
    but its not happening.
    i am giving the code below

    my $sql = qq{ SELECT node_name FROM customer_node_history };
    my $sth = $zdb->prepare( $sql ) or die "Error preparing sql: $zdb->errstr";
    $sth->execute() or die "Error executing sql: $zdb->errstr";
    print($sth);


    Last edited by Raj on Wed Dec 10, 2008 6:36 am; edited 2 times in total (Reason for editing : Do not post copyright material.)
    Raj
    Raj
    Admin
    Admin


    Posts : 3
    Join date : 2008-11-26
    Age : 40
    Location : Bangalore

    perl beginner Empty Re: perl beginner

    Post  Raj Wed Dec 10, 2008 6:33 am

    Anitha wrote:hi,
    Iam very new to perl.
    Here iam trying to connect to Database and trying to fetch the node names of customer by using sql. i am expecting that my query needs to be prepared and executed and returns the reuslts.
    but its not happening.
    i am giving the code below

    my $sql = qq{ SELECT node_name FROM customer_node_history };
    my $sth = $zdb->prepare( $sql ) or die "Error preparing sql: $zdb->errstr";
    $sth->execute() or die "Error executing sql: $zdb->errstr";
    print($sth);

    everything looks fine to me except the fetch part is missing. Very Happy
    it should be somthing like this
    my $sql = qq{ SELECT node_name FROM customer_node_history };
    my $sth = $zdb->prepare( $sql ) or die "Error preparing sql: $zdb->errstr";
    $sth->execute() or die "Error executing sql: $zdb->errstr";
    while(($name)=$sth->fetchrow)
    {
    print(" Values are :- $name");
    }

    Cheers,
    Raj
    avatar
    vikram
    Newbie
    Newbie


    Posts : 2
    Join date : 2008-11-26

    perl beginner Empty Re: perl beginner

    Post  vikram Wed Dec 10, 2008 6:44 am

    Its advisable to use some sort of range in the where clause like

    my $sql = qq{ SELECT node_name FROM customer_node_history where customer_id = :1 };

    and $sth->execute($cust_id) or die "Error executing sql: $zdb->errstr";

    Enjoy,
    Vikram

    Sponsored content


    perl beginner Empty Re: perl beginner

    Post  Sponsored content


      Current date/time is Sun May 19, 2024 10:40 am