Prepared SQL statement in Perl
<p>I'm very new to Perl, I'm trying to overcome the initial learning curve.</p>
<p>I have the following SQL statement:</p>
<pre><code>SELECT 
    node_id 
FROM 
    pagenodes
INNER JOIN 
    pageproducts 
ON 
    pagenodes.node_id = pageproducts.nodeid
INNER JOIN 
    products 
ON 
    pageproducts.prodid = products.prodid 
WHERE 
    products.prodid  = ?
LIMIT 1
</code></pre>
<p>As you can see this has LIMIT 1 set in the query, I'm trying to perform this query from a Perl script, and set the result to a variable.</p>
<p>So far I have the following:</p>
<pre><code>my $sql =
    'SELECT 
        node_id 
    FROM 
        pagenodes
    INNER JOIN 
        pageproducts 
    ON 
        pagenodes.node_id = pageproducts.nodeid
    INNER JOIN 
        products 
    ON 
        pageproducts.prodid = products.prodid 
    WHERE 
        products.prodid  = ?
    LIMIT 1';
    
    my $sth = $dbh-&gt;prepare($sql);
    my $sth-&gt;execute();
</code></pre>
<p>My question is, how can I pass in <code>$prod_id</code> as the WHERE paramater, and how can I set the result to a variable. Thanks</p>