猿问

将 stdClass 转换为数组时出现问题

我已将我的网站之一转换为使用 PDO 数据库查询。除了一个查询之外,所有查询都运行良好,我花了一整天的时间试图解决这个问题,但没有任何结果对我有用,所以作为最后的手段,我在这里寻求一些建议。


这是我遇到问题的功能


    public function getTransactions($iProfileId)

    {


        $rStmt = Db::getInstance()->prepare('SELECT * FROM' . Db::prefix(DbTableName::GIFT_TX) .

                                            'WHERE profileId = :profileId ' .

                                            'ORDER BY createDate ASC, txId ASC');

        

        $rStmt->bindValue(':profileId', $iProfileId, \PDO::PARAM_INT);


        $rStmt->execute();

        $this->getTxs = $rStmt->fetch(\PDO::FETCH_OBJ);

        Db::free($rStmt);

        

                    

        return $this->getTxs;

    }

    


即使有许多其他行并且作为对象,它也会返回一行



object(stdClass)#47 (8) { ["txId"]=> string(1) "8" ["profileId"]=> string(3) "861" ["type"]=> string(6) "credit" ["credits"]=> string(2) "25" ["createDate"]=> string(19) "2020-06-26 10:48:55" ["isDelete"]=> string(1) "0" ["price"]=> string(4) "0.05" ["merchant"]=> string(6) "PayPal" }



我需要将其作为数组返回并获取 profileId = :profileId 的所有行


我已经尝试了网上能找到的所有方法,但都没有成功。


MM们
浏览 118回答 1
1回答

猛跑小猪

试试这个代码$this->getTxs = $rStmt->fetchAll(PDO::FETCH_ASSOC);如有疑问,请查看以下 URL:https://www.php.net/manual/en/pdostatement.fetchall.php
随时随地看视频慕课网APP
我要回答