如何修复bind_param“无法通过参数”

时间:2019-05-05 19:22:42

标签: php mysql

我使用的网址:../ accessogiornaliero.php?idplayer = 45ccf2a79ec84c

accessogiornaliero.php:

$query = $mysqli->prepare('UPDATE player SET lastLogin = ?,loginstreak = ? WHERE idplayer = ?');
            $query->bind_param("sis", $qdata, $loginStreak, $_GET["idplayer"]);
            $qdata = $now->format('Y-m-d H:i:s');
            $query->execute();

错误:

[05-May-2019 21:19:05 Europe/Rome] PHP Fatal error:  Uncaught Error: Cannot pass parameter 3 by reference in .../accessogiornaliero.php:62
Stack trace:
#0 {main}
  thrown in .../accessogiornaliero.php on line 62

我在哪里错了?

2 个答案:

答案 0 :(得分:1)

尝试在

之前分配值
  $query = $mysqli->prepare('UPDATE player SET lastLogin = ?,loginstreak = ? WHERE idplayer = ?');
        $qdata = $now->format('Y-m-d H:i:s');
        $idplayer =  $_GET["idplayer"];
        $query->bind_param("sis", $qdata, $loginStreak,  $idplayer );
        $query->execute();

答案 1 :(得分:1)

我认为您正在尝试传递DateTime对象作为引用?

[05-May-2019 21:19:05 Europe/Rome]$qdata变量上

我认为您可以/应该重写

$query = $mysqli->prepare('UPDATE player SET lastLogin = ?,loginstreak = ? WHERE idplayer = ?');
            $query->bind_param("sis", $qdata, $loginStreak, $_GET["idplayer"]);
            $qdata = $now->format('Y-m-d H:i:s');
            $query->execute();

使用更简单的MySQL NOW()函数。

$query = $mysqli->prepare('UPDATE player SET lastLogin = NOW(), loginstreak = ? WHERE idplayer = ?');
            $idplayer =  $_GET["idplayer"];
            $query->bind_param("is", $loginStreak, $idplayer);                
            $query->execute();