Strict Standards: Only variables should be passed by reference

不打扰是莪最后的温柔 提交于 2019-12-20 05:13:16

问题


My PHP script is displaying an error:

Strict Standards: Only variables should be passed by reference in C:\....*.php on line 551

The code is below:

function trinity_premissions()
{
        global $ACC_PDO, $WEB_PDO, $a_user, $db_translation;

        $end = false;

        $res = $WEB_PDO->prepare("SELECT acc_login, gmlevel FROM `accounts_more` WHERE UPPER(acc_login) = :acc");
/* 551 */$res->bindParam(':acc', strtoupper($a_user[$db_translation['login']]), PDO::PARAM_STR);
        $res->execute();

        if ($res->rowCount() == 1)
        {
                $s2 = $res->fetch(PDO::FETCH_ASSOC);
                if ($s2['gmlevel']<>'')
                {
                        return $s2['gmlevel'];
                }
        }
        unset($res);
}

I don't know what the problem is. Can anyone help me?


回答1:


Your second parameter 'strtoupper($a_user[$db_translation['login']])' must be a reference to a variable.

doc : Ref to bindparam

the 'mixed &$variable' in the doc say that it must be a reference (it's the '&')

you can create a variable, and put the result of 'strtoupper($a_user[$db_translation['login']])' into it. For example :

$foo = strtoupper($a_user[$db_translation['login']]);
$res->bindParam(':acc', $foo, PDO::PARAM_STR);

Hope this help




回答2:


use bindValue() because bindParam() second arg is a reference like

$res->bindValue(':acc', strtoupper($a_user[$db_translation['login']]));

if you want to use bindParam then you have to store your statement into one variable and pass that variable as an argument. like.

$test = strtoupper($a_user[$db_translation['login']];
$res->bindParam(':acc', $test), PDO::PARAM_STR);



回答3:


Use:

$param = strtoupper($a_user[$db_translation['login']]);
$res->bindParam(':acc', $param, PDO::PARAM_STR);


来源:https://stackoverflow.com/questions/16765099/strict-standards-only-variables-should-be-passed-by-reference

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