Jump to content

Undefined variable: pdo


I-AM-OBODO
Go to solution Solved by CroNiX,

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
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)
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.