将数据从SQL查询返回到数组中

时间:2013-06-13 20:41:04

标签: php mysql arrays

我有以下代码:

$aResult = $db->exec_sql($sql);

    //dlog2("matt", __line__, $aResult);
        print_r($aResult);


        $params = array(
                        'store_id' => $aResult['iStoreID'],
                        'user_id' => $aResult['iUserID'],
                        'store_name' => $aResult['cStoreName'],
                        'store_url' => $aResult['cStoreURL'],
                        'rid' => $aResult['cRID'],
                        'affiliate_id' => $aResult['iAffiliateID'],
                        'team_id' => $aResult['iTeamID'],
                        'bizOP' => $aResult['cDefaultBizOpp'],
                        'showBizOPp' => $aResult['iShowBizOppDropdown'],
                        'boPosting' => $aResult['iEnableBOPosting'],
                        'brandinglevel' => $aResult['iBrandingLevel']
        );

       // dlog2("matt", __line__, $params);
        print_r($params);

$ aResult是一个数组,其中数据按列标题进行组织。但是,当我尝试将数据移动到$ params时,它返回一个空数组。有什么建议?

我们的想法是设置一个可以在$ params上做外部帖子的cron

1 个答案:

答案 0 :(得分:1)

$ aResult是否已使用PDO检索?如果是这样使用哪种方法?你用过fetch吗?或者fetchAll如果你使用$ aResult ['item]上面的方法你应该使用fetch,如果没有你使用fetchAll你需要$ aResult [0] ['item']否则会生成一个空数组。根据给出的信息,这是我的猜测