Database::getRows PHP Method

getRows() public method

public getRows ( $sql ) : array
return array of objects|false
    public function getRows($sql)
    {
        $res = $this->doQuery($sql);
        if ($res && $this->getNumRows($res)) {
            $ret = array();
            while ($res && ($row = $this->fetchObject($res))) {
                $ret[] = $row;
            }
            $this->freeResult($res);
            return $ret;
        }
        return false;
    }

Usage Example

Example #1
0
    /**
     * @param Database $db
     * @param array $runRows: one or more rows from the `runs` table.
     * @return array with properties 'runs' and 'userAgents'
     */
    public static function getDataFromRunRows(Database $db, $runRows)
    {
        $userAgentIDs = array();
        $runs = array();
        foreach ($runRows as $runRow) {
            $runInfo = array('id' => $runRow->id, 'name' => $runRow->name, 'url' => $runRow->url);
            $runUaRuns = array();
            // Get list of useragents that this run is scheduled for
            $runUaRows = $db->getRows(str_queryf('SELECT
					status,
					useragent_id,
					results_id
				FROM
					run_useragent
				WHERE run_useragent.run_id = %u;', $runRow->id));
            if ($runUaRows) {
                foreach ($runUaRows as $runUaRow) {
                    // Add UA ID to the list. After we've collected
                    // all the UA IDs we'll perform one query for all of them
                    // to gather the info from the useragents table
                    $userAgentIDs[] = $runUaRow->useragent_id;
                    if (!$runUaRow->results_id) {
                        $runUaRuns[$runUaRow->useragent_id] = array('runStatus' => 'new');
                    } else {
                        $runresultsRow = $db->getRow(str_queryf('SELECT
								client_id,
								status,
								total,
								fail,
								error
							FROM runresults
							WHERE id = %u;', $runUaRow->results_id));
                        if (!$runresultsRow) {
                            $this->setError('data-corrupt');
                            return;
                        }
                        $runUaRuns[$runUaRow->useragent_id] = array('useragentID' => $runUaRow->useragent_id, 'clientID' => $runresultsRow->client_id, 'failedTests' => $runresultsRow->fail, 'totalTests' => $runresultsRow->total, 'errors' => $runresultsRow->error, 'runStatus' => self::getRunresultsStatus($runresultsRow), 'runResultsUrl' => swarmpath('result/' . $runUaRow->results_id), 'runResultsLabel' => $runresultsRow->status != ResultAction::$STATE_FINISHED ? '' : ($runresultsRow->error > 0 ? $runresultsRow->error : ($runresultsRow->fail > 0 ? $runresultsRow->fail : $runresultsRow->total)));
                    }
                }
                natcaseksort($runUaRuns);
                $runs[] = array('info' => $runInfo, 'uaRuns' => $runUaRuns);
            }
        }
        // Get information for all encounted useragents
        $swarmUaIndex = BrowserInfo::getSwarmUAIndex();
        $userAgents = array();
        foreach ($userAgentIDs as $userAgentID) {
            if (!isset($swarmUaIndex->{$userAgentID})) {
                throw new SwarmException("Job {$jobID} has runs for unknown brower ID `{$userAgentID}`.");
            } else {
                $userAgents[$userAgentID] = (array) $swarmUaIndex->{$userAgentID};
            }
        }
        natcaseksort($userAgents);
        return array('runs' => $runs, 'userAgents' => $userAgents);
    }
All Usage Examples Of Database::getRows