小编kin*_*ute的帖子

在没有变量的情况下直接使用函数返回

对不起,我的英文,在Google上找不到正确的单词,以找出为什么会这样.一定很容易解决!

我正在使用PHP 7,我想使用函数提供的返回查询(绑定它).如果我直接调用我的绑定函数中的函数,它什么都不返回.如果我在外面调用它,比如$ var = function($ a)并在绑定函数中使用$ var,它就可以了.

我不明白为什么我不能直接使用这个功能?如果我在函数的参数中执行此操作(如函数getID($ this-> getName(1)))它可以工作.为什么不在这里?代码:

不行

        $this->bdd->query("UPDATE stats_of_the_days
                            SET winner_firstsolves = :winner_fs
                            WHERE id = :stat_id");

        $this->bdd->bind("winner_fs", $this->getTodayWinnerFs($winnerID), PDO::PARAM_INT);
        $this->bdd->bind("stat_id", $statID, PDO::PARAM_INT);

        $this->bdd->execute();
Run Code Online (Sandbox Code Playgroud)

Works(使用变量来调用/存储函数/返回)

    $var = $this->getTodayWinnerFs($winnerID);

    $this->bdd->query("UPDATE stats_of_the_days
                        SET winner_firstsolves = :winner_fs
                        WHERE id = :stat_id");

    $this->bdd->bind("winner_fs", $var, PDO::PARAM_INT);
    $this->bdd->bind("stat_id", $statID, PDO::PARAM_INT);


    $this->bdd->execute();
Run Code Online (Sandbox Code Playgroud)

这个功能非常基础

public function getTodayWinnerFs($userID)
    {
      // query stuff
      return $this->bdd->resultObj()->Wins;
    }
Run Code Online (Sandbox Code Playgroud)

返回函数的示例

var_dump($this->getTodayWinnerFs(494));
// string(2) "13"
Run Code Online (Sandbox Code Playgroud)

我的db pdo类中的"bind"函数

        public function bind($param, $value, $type = null)
        {
            if (is_null($type)) {
                switch …
Run Code Online (Sandbox Code Playgroud)

php pdo bind return function

2
推荐指数
1
解决办法
97
查看次数

标签 统计

bind ×1

function ×1

pdo ×1

php ×1

return ×1