PHP和MySQLi-无法在中通过引用传递参数2

PHP和MySQLi-无法在中通过引用传递参数2,php,mysqli,Php,Mysqli,我正在尝试创建一个函数,该函数将检查更新并插入一些数据,但我在第一步遇到了一个问题,$stmt->bind_param表示没有通过引用或类似的方式传递参数 我已在下面附上功能代码: public function killTarget($killerid,$victimiid,$victimcode) { if ($this->checkUsercode($victimcode,$victimiid)) { $stmt =

我正在尝试创建一个函数,该函数将检查更新并插入一些数据,但我在第一步遇到了一个问题,$stmt->bind_param表示没有通过引用或类似的方式传递参数

我已在下面附上功能代码:

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");
            }
        }

    }

将0设为变量或直接将其包含在查询中

$zero = 0;
$stmt->bind_param("ii", $zero, $victimiid);
您不能在mysqli中执行此操作:

$stmt->bind_param("ii",0,$victimiid);
0必须是一个变量

试试这个:

$zero = 0;
$stmt->bind_param("ii",$zero,$victimiid);
小心!接受对变量的引用,而不是常量值。因此,您必须创建一个变量来保存该0,然后引用该变量

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

我忘了提到问题发生在函数的第一行:$stmt->bind_paramii,0,$victimid;我建议使用PDO对象,在这种情况下,您可以执行$stmt->executearray0,$victimiid;而不是用bind_param或类似的东西绑定param?下次请更加注意确切的错误消息,并在适当的时候将它们发布在这里。这些消息是为了帮助您,而不仅仅是为了烦扰您。我还想添加全局变量,如定义'global_string','test';也需要转换。