Jump to content

Undefined variable: pdo


I-AM-OBODO

Recommended Posts

Hi guys.

 

why is my function error: undefined varable pdo?

 

Thanks

 

 

function referralCount($uid,$reflvl)
{

$stmt= $pdo->query("SELECT * FROM scraffiliateusr WHERE usrinvby='$uid'");
$nusrref1 = $stmt->rowCount();
//$arrusrref1 = $stmt->fetch(PDO::FETCH_LAZY);

$reflvl1=$nusrref1;
$ttlreflvl2="0";
$ttlreflvl3="0";

for ($i=0; $i<$nusrref1; $i++)
{
$arrusrref1 = $stmt->fetch(PDO::FETCH_LAZY);
    $stmt= $pdo->query("SELECT * FROM scraffiliateusr WHERE usrinvby='$arrusrref1[0]'");
    $nusrref2 = $stmt->rowCount();
    //$arrusrref2 = $stmt->fetch(PDO::FETCH_LAZY);
    $ttlreflvl2=$ttlreflvl2+$nusrref2;


        for ($j=0; $j<$nusrref2; $j++)
        {
        $arrusrref2 = $stmt->fetch(PDO::FETCH_LAZY);

        $stmt= $pdo->query("SELECT * FROM scraffiliateusr WHERE usrinvby='$arrusrref2[0]'");
        $nusrref3 = $stmt->rowCount();
        //$arrusrref3 = $stmt->fetch(PDO::FETCH_LAZY);

        $ttlreflvl3=$ttlreflvl3+$nusrref3;
        }
}
$reflvl2=$ttlreflvl2;
$reflvl3=$ttlreflvl3;
if($reflvl=='1')
{
return($reflvl1);
}
elseif($reflvl=='2')
{
return($reflvl2);
}
elseif($reflvl=='3')
{
return($reflvl3);
}

}
Link to comment
https://forums.phpfreaks.com/topic/293209-undefined-variable-pdo/
Share on other sites

You would need something along the lines of:

$con = new PDO("$this->db:host=$this->host;dbname=$this->dbname",$this->user,$this->pass);

If you wanted to use this in a function then you need to make the function aware of your database connection (variable scope)

An easy way of accomplishing this is through dependency injection - simply pass the variable to your function in the form of an argument.

function referralCount($uid,$reflvl,$DB)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.