try { $iterator->checkConstraints(); $runner->fail('Why was I able to constrain an iterator for strong_guy to value that should be wrong?'); } catch (InvalidQueryRowException $exc) { $runner->pass(); } }); /** * Test using as an iterator in a foreach loop */ \Murphy\Test::add(function ($runner) { \Murphy\Fixture::load(dirname(__FILE__) . '/../on_clause.class.php.murphy/fixture.php')->execute(); $conn = new Connection('localhost', 'plusql', 'plusql', 'plusql'); $conn->connect(); $query = new Query('SELECT * FROM strong_guy', $conn->link()); $iterator = new QueryIterator($query, 'strong_guy', 0); $pairs = array('strong_guy_id' => 1); $iterator->constrainKeys($pairs); if ($iterator->strong_name == 'Strongy Strongo') { $runner->pass(); } else { $runner->fail('Could not get value for strong_name from strong_guy iterator'); } $conn = NULL; \Murphy\Fixture::load(dirname(__FILE__) . '/../on_clause.class.php.murphy/fixture.php')->also(dirname(__FILE__) . '/fixture.php')->execute(function ($aliases) use(&$conn) { $deets = $aliases['plusql']; $conn = new Connection($deets[0], $deets[1], $deets[2], $deets[3]); $conn->connect(); }); $expected_output = trim(' Strong 1:Weak 1:Rogue 1:French 1
/** * @param object PHP Eclipse instance * @param string db query * @param array PEAR::Pager options * @param boolean Disable pagination (get all results) * @return array with links and paged data * @author Matte Edens <*****@*****.**> * @see http://sourceforge.net/projects/eclipselib/ */ function Pager_Wrapper_Eclipse(&$db, $query, $pager_options = array(), $disabled = false) { if (!$disabled) { require_once ECLIPSE_ROOT . 'PagedQuery.php'; $query = new PagedQuery($db->query($query), $pager_options['perPage']); $totalrows = $query->getRowCount(); $numpages = $query->getPageCount(); $whichpage = isset($_GET[$pager_options['urlVar']]) ? (int) $_GET[$pager_options['urlVar']] - 1 : 0; if ($whichpage >= $numpages) { $whichpage = $numpages - 1; } $result = $query->getPage($whichpage); } else { $result = $db->query($query); $totalrows = $result->getRowCount(); $numpages = 1; } if (!$result->isSuccess()) { return PEAR::raiseError($result->getErrorMessage()); } if (!array_key_exists('totalItems', $pager_options)) { $pager_options['totalItems'] = $totalrows; } $page = array(); require_once ECLIPSE_ROOT . 'QueryIterator.php'; for ($it = new QueryIterator($result); $it->isValid(); $it->next()) { $page['data'][] =& $it->getCurrent(); } require_once 'Pager/Pager.php'; $pager = Pager::factory($pager_options); $page['links'] = $pager->links; $page['totalItems'] = $pager_options['totalItems']; $page['page_numbers'] = array('current' => $pager->getCurrentPageID(), 'total' => $numpages); $page['perPageSelectBox'] = $pager->getperpageselectbox(); list($page['from'], $page['to']) = $pager->getOffsetByPageId(); $page['limit'] = $page['to'] - $page['from'] + 1; if ($disabled) { $page['links'] = ''; $page['page_numbers'] = array('current' => 1, 'total' => 1); } return $page; }
public function next() { if ($this->data = pg_fetch_assoc($this->result)) { $this->valid = true; $this->key += 1; } else { $this->valid = false; } } public function valid() { return $this->valid; } } //implementation $qi = new QueryIterator("usersDB", "user1", "password1"); $qi->execute("select name, email from users"); while ($qi->valid()) { print_r($qi->current()); $qi->next(); } /* example output Array ( [name] => Afif [email] => mayflower@phpxperts.net ) Array (