PHP and MySQLi - Cannot pass parameter 2 by reference in

烂漫一生 提交于 2019-11-26 14:48:56

问题


i am trying to make a function which will check update and insert some datas but i am having an issue in the first step where the $stmt->bind_param is saying that is not passing parameters by reference or something like that.

I searched over internet but nothing was around so i dont know what to do with it.

I have attached below the function code:

public function killTarget($killerid,$victimiid,$victimcode)
    {

        if ($this->checkUsercode($victimcode,$victimiid))
        {
            $stmt = $this->_db->prepare("UPDATE users SET status =? WHERE user_id =?");
            $stmt->bind_param("ii",0,$victimiid);

            if ($stmt->execute())
            {
                $stmt->store_result();
                $stmt->fetch();

                $stmt = $this->_db->prepare("SELECT victim_id FROM target WHERE killer_id = ?");
                $stmt->bind_param("i",$victimiid);

                if ($stmt->execute())
                {
                    $stmt->store_result();
                    $stmt->bind_result($targetid);
                    $stmt->fetch();

                    $stmt = $this->_db->prepare("INSERT INTO target (killer_id, victim_id) VALUES (?,?)");
                    $stmt->bind_param("ii",$killerid,$targetid);

                    if ($stmt->execute())
                    {
                        $stmt->store_result();
                        $stmt->fetch();
                        $stmt->close();
                    }
                }
            }
            else
            {
                Main::setMessage("targets.php",$this->_db->error,"alert-error");
            }
        }

    }

Well any suggestion is appreciated.

Thank you


回答1:


You cannot do this in mysqli:

$stmt->bind_param("ii",0,$victimiid);

The 0 needs to be a variable.

Try this:

$zero = 0;
$stmt->bind_param("ii",$zero,$victimiid);



回答2:


Watch out! mysqli_stmt::bind_param accepts a reference to a variable, not a constant value. Therefore you have to create a variable to hold that 0 and then reference that variable instead.

$i = 0;
$stmt->bind_param("ii", $i, $victimiid);



回答3:


Make 0 a variable or include it directly in your query.

$zero = 0;
$stmt->bind_param("ii", $zero, $victimiid);


来源:https://stackoverflow.com/questions/14566929/php-and-mysqli-cannot-pass-parameter-2-by-reference-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!