maximebf / atomik

Micro framework for PHP 5.3+ [UNMAINTAINED]
MIT License
46 stars 18 forks source link

Add $afterWhere to selectValue() in Db.php #35

Closed bootswithdefer closed 3 years ago

bootswithdefer commented 10 years ago

The other select functions have afterWhere, would be nice to have it in selectValue too.

JPFrancoia commented 8 years ago

Hi,

A simple count query like that:

$total_users = $this['db']->count('python_users');

Leads to an error:

Notice: Undefined variable: afterWhere in /home/djipey/informatique/servers/site_atomik/vendor/atomik/atomik/src/plugins/Db.php on line 108

Looking at the code:

    public function selectValue($tableName, $column, $where = null)
    {
        $stmt = $this->executeSelect($tableName, $column, $where, $afterWhere);
        return $stmt->fetchColumn();
    }

    /**
     * Executes a SELECT COUNT(*) on $tableName
     * 
     * @param string $tableName
     * @param array|string $where
     * @return int
     */
    public function count($tableName, $where = null)
    {
        return $this->selectValue($tableName, 'COUNT(*)', $where);
    }

You can see that the function count relies on selectValue, but does not pass the $afterWhere argument to this function. It causes a bug. I will make a PR.