Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/255.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/66.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将stdClass转换为数组的问题_Php_Mysql_Database_Pdo - Fatal编程技术网

Php 将stdClass转换为数组的问题

Php 将stdClass转换为数组的问题,php,mysql,database,pdo,Php,Mysql,Database,Pdo,我已将我的一个网站转换为使用PDO数据库查询。除了一个问题外,所有的查询都运行得很好,我花了一整天的时间试图解决这个问题,但没有任何东西对我有效,因此作为最后手段,我在这里征求一些建议 这就是我遇到的问题 public function getTransactions($iProfileId) { $rStmt = Db::getInstance()->prepare('SELECT * FROM' . Db::prefix(DbTableName::GI

我已将我的一个网站转换为使用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的所有行

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

试试这段代码

$this->getTxs = $rStmt->fetchAll(PDO::FETCH_ASSOC);
    
如果有疑问,请查看以下URL:

https://www.php.net/manual/en/pdostatement.fetchall.php

您只需调用一次
fetch()
,然后使用
\PDO::fetch_OBJ
调用它,因此最终将有一行作为对象!PHP文档说。。。PDO::FETCH_OBJ(整数)指定fetch方法应将每一行作为一个对象返回,该对象的属性名称与结果集中返回的列名相对应。我有200多个函数,这是唯一有问题的函数。在PDO::fetch_OBJ上:返回一个匿名对象,其属性名称与结果集中返回的列名相对应结果setTry
fetchAll()
\PDO::FETCH\u ASSOC