logo
Ask your Symfony questions! Pay money and get answers fast! (more info)

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.

$10
A statement pager for the old versions of Creole

Hey, everyone, I am overwhelmed with work this weekend so I am going to outsource 2 small projects to the excellent programmers of Symfony Experts.

The first project is real simple. I need the great statement pager that Nicolas Martin did, redone to work with the old syntax of pre-PDO versions of Creole. In other words, this:

$this->statement->execute();


needs to become

$this->statement->executeQuery();


and

$this->statement->rowCount()


needs to become whatever the earlier version of that method used to be.

I do not have time to look up the old API, so I offer it here for someone else to do.

Change all the methods to their older versions.

This question has been answered.

Lawrence Krubner | 05/16/10 at 3:21pm Edit


(3) Responses

See a threaded view of answers?

Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

  • avatar
    Last edited:
    05/17/10
    11:32am
    Arturo Linares says:


    class statementPager extends sfPager
    {
    protected $resultsetArray = array();
    protected $query = '';

    public function __construct($class = null, $maxPerPage = 10)
    {
    parent::__construct($class, $maxPerPage);
    }

    public function setStatement($statement, $query)
    {
    $this->statement = $statement;
    $this->query = $query;
    }

    public function init()
    {
    $rs = $this->statement->executeQuery($this->query);

    $this->setNbResults($rs->getRecordCount());

    if (($this->getPage() == 0 || $this->getMaxPerPage() == 0))
    {
    $this->setLastPage(0);
    }
    else
    {
    $this->setLastPage(ceil($this->getNbResults() / $this->getMaxPerPage()));
    }
    }

    public function getResults()
    {

    if (($this->getPage() == 0 || $this->getMaxPerPage() == 0))
    {
    $this->setLastPage(0);
    }
    else
    {
    $this->setLastPage(ceil($this->getNbResults() / $this->getMaxPerPage()));
    }

    $row_num = 1;
    while ($resultset = $this->statement->executeQuery())
    {
    if ($row_num > $this->getMaxPerPage()*($this->getPage()-1)
    and $row_num <= ($this->getPage()*$this->getMaxPerPage() ))
    {
    $this->resultsetArray[] = $resultset;
    }
    $row_num++;
    }

    return $this->resultsetArray;
    }

    public function retrieveObject($offset)
    {
    return $this->resultsetArray[$offset];

    }
    }

    // you can call it like this:

    $connection = Propel::getConnection();
    $query = 'SELECT * from account';

    $statement = $connection->createStatement();

    $pager = new statementPager(null, 10);
    $pager->setStatement($statement, $query);
    $pager->setPage(1);
    $pager->init();

  • avatar
    Last edited:
    05/16/10
    4:01pm
    Lawrence Krubner says:

    Looks good, but I won't be able to test it till very late tonight. Thanks!

  • avatar
    Last edited:
    05/17/10
    11:31am
    Lawrence Krubner says:

    The while loop needs to be

     while ($resultset->next())


    but otherwise this was perfect. thanks.

This question has expired.





Current status of this question: Completed



Warning: Please do not give out any FTP or ssh credentials to anyone, unless you trust them completely. Giving out login details is dangerous.

If the asker does not get an answer then they have 10 days to request a refund.