Object of type mysqli_result error in old vBulletin product

54 Views Asked by At

I am trying to update an old vBulletin product and it keeps throwing an error for me.

Cannot use object of type mysqli_result as array in C:\wamp\www\mem_payment.php on line 124

Line 124:

$vbma->setCustomerNumber(unserialize($purchase['info']), $product['pur_group'], false, $userinfo);

Line 102 - 130

$purchase = $vbulletin->db->query_first("SELECT * FROM " . TABLE_PREFIX .
        "ma_purchases WHERE id = '" . $id . "'");
    $order = unserialize($purchase['order']);
    if ($order[0] !== $vbulletin->GPC['business'])
    {
        $status_code = '503 Service Unavailable';
        // Paypal likes to get told its message has been received  
        if (SAPI_NAME == 'cgi' or SAPI_NAME == 'cgi-fcgi')
        {
            header('Status: ' . $status_code);
        }
        else
        {
            header('HTTP/1.1 ' . $status_code);
        }
    }
    unset($order[0]);
    if ($purchase and !in_array($order[1], array('renew', 'upgrade')))
    {
        $product = $vbulletin->db->query_read("SELECT pur_group FROM " . TABLE_PREFIX .
            "ma_products WHERE id = '" . $order[1] . "'");
        $userinfo = fetch_userinfo($purchase['userid']);
        $vbma->setCustomerNumber(unserialize($purchase['info']), $product['pur_group'], false,
            $userinfo);
        $rand = rand($vbulletin->options['memarea_numstart'], $vbulletin->options['memarea_numend']);
        $licnum = substr(md5($prodid . rand(0, 20000) . $rand . $rand), 0, rand(10, $vbulletin->
            options['memarea_custnumleng']));
        $licensedm = datamanager_init('License', $vbulletin, ERRTYPE_ARRAY);
        $licensedm->setr('userid', $userinfo['userid']);

I have been reading numerous questions regarding this error stating to essentially:

  • define your query

  • query your query

  • then associate the query

IE:

$query = "SELECT 1";
$result = $mysqli->query($query);
$followingdata = $result->fetch_assoc()

Almost all of the answers are along those lines, although I am failing to see where this needs to be done.

I'm not sure if it has anything to do with the function, but I will add that as well:

function setCustomerNumber($ma_info, $usergroup = '', $usevb = true, $userinfo = '')
    {
        if ($usevb == false)
        {
            $this->vbulletin->userinfo = &$userinfo;
        }
        $fcust = $this->fields['custnum'];
        $fpass = $this->fields['mpassword'];
        $finfo = $this->fields['info'];
        $userdm = datamanager_init('User', $this->vbulletin, ERRTYPE_ARRAY);
        $userinfo = fetch_userinfo($this->vbulletin->userinfo['userid']);
        $userdm->set_existing($userinfo);
        if (!$this->vbulletin->userinfo["$fcust"] and !$this->vbulletin->userinfo["$fpass"])
        {
            $rand = rand($this->vbulletin->options['memarea_numstart'], $this->vbulletin->
                options['memarea_numend']);
            $num = $this->vbulletin->options['custnum_prefix'] . substr(md5($rand), 0, $this->
                vbulletin->options['memarea_custnumleng'] - strlen($this->vbulletin->options['custnum_prefix']));
            $userdm->set($fcust, $num);
            $pass = substr(md5(time() . $num . $rand . rand(0, 2000)), 0, $this->vbulletin->
                options['memarea_custnumleng']);
            $userdm->set($fpass, $pass);
            $this->sendCustomerInfo($this->vbulletin->userinfo['userid'], $this->vbulletin->
                userinfo['username'], $this->vbulletin->userinfo['email'], $num, $pass);
        }
        if ($usergroup or $usergroup !== '' or $usergroup !== '0')
        {
            if ($usergroup != $this->vbulletin->userinfo['usergroupid'])
            {
            $ma_info['oldgroup'] = $this->vbulletin->userinfo['usergroupid'];
            $userdm->set('usergroupid', $usergroup);
            }
        }
        if ($ma_info)
        {
            $ma_info = serialize($ma_info);
            $userdm->set($finfo, $ma_info);
        }

        $userdm->pre_save();
        if (count($userdm->errors) == 0)
        {
            $userdm->save();
            return true;
        }
        else
        {
            var_dump($userdm->errors);
            return false;
        }
    }

Why am I getting this error? In your answer could you please explain to me what needs to be changed.

1

There are 1 best solutions below

1
shingo On

query_read returns mysqli_result&, you need convert it to an array first.

$query_result = $vbulletin->db->query_read(...);
$product = $query_result->fetch_assoc();