Caching wrapper for pg_affected_rows()
This appears bugged in php 5.3 and postgres 9.1 returning the number of rows modified by a statement
@return int
3485
public function numAffectedRows()
    {
        if( !isset( $this->affectedRows ) ) {
            $this->affectedRows = pg_affected_rows( $this->resource );
        }
        return $this->affectedRows;
    }
1364012
private function getCommentsCountResetQuery($postTableName)
    {
        switch ($this->getConnection()->getDriver()->getDatabasePlatform()->getName()) {
            case 'postgresql':
                return sprintf('UPDATE %s SET comments_count = 0', $postTableName);

            default:
                return sprintf('UPDATE %s p SET p.comments_count = 0', $postTableName);
        }
    }
955319
public function affectedRows($which_connection='')
    {
        if ($which_connection == '') {
            $which_connection=$this->default_db;
        }
        $con = $this->connections[$which_connection];

        return $con->Affected_Rows();
    }
474025
public function getRowsCountRecursive()
    {
        $totalCount = 0;
        foreach ($this->rows as $row) {
            $subTable = $row->getSubtable();
            if ($subTable) {
                $count = $subTable->getRowsCountRecursive();
                $totalCount += $count;
            }
        }

        $totalCount += $this->getRowsCount();
        return $totalCount;
    }
407028
public function columnCount()
    {

        switch ($this->mode) {

            case "mysql":
                $columns = $this->result->field_count;
                break;

            case "postgres":
            case "redshift":
                $columns = pg_num_fields($this->result);
                break;

            case "odbc":
                $columns = odbc_num_fields($this->result);
                break;

            case "sqlite":
                $columns = $this->result->numColumns();
                break;

            case "mssql":
                $columns = mssql_num_fields($this->result);
                break;

            case "mssqlsrv":
                $columns = sqlsrv_num_fields($this->result);
                break;
        }

        if ($columns === false || $columns < 0) {
            throw new \Exception("Failed to get the column count from the result set");
        }

        return $columns;
    }
197832
public function total()
	{
		// Note that we do not need to parse includes at this stage, as includes do not effect
		// the primary result set, and thus do not effect the count. whereRelated() could effect
		// the count, but that method is not currently in use.
		//
		// We also reset the 'select' clause to avoid pulling unnecessary records and reset
		// the 'order by' clause to avoid referenced fields in the aforementioned 'select' clauses
		// that mgiht have been removed. Neither of these should have any effect on a count.
		$first = $this->deselect()
		              ->select($this->getQualifiedFieldName($this->getPrimaryKey()), 'count', true)
		              ->unordered()
		              ->rows(false)
		              ->first();
		              //->count;

		$total = $first ? (int)$first->count : 0;

		$this->reset();

		return $total;
	}
1186230
public function count()
    {
        if ($this->rowCount !== null) {
            return $this->rowCount;
        }

        $qbOriginal = $this->getQueryBuilder();
        $qb = clone $qbOriginal;

        $dqlParts = $qb->getDQLParts();
        $groupParts = $dqlParts['groupBy'];

        /*
         * Reset things
         */
        $qb->setFirstResult(null)
            ->setMaxResults(null)
            ->resetDQLParts([
            'orderBy',
            'select',
            ]);

        if (count($groupParts) > 1) {
            /*
             * UGLY WORKAROUND!!! @todo
             */
            // more than one group part...tricky!
            // @todo finde something better...
            $qb->resetDQLPart('groupBy');
            $qb->select('CONCAT('.implode(',', $groupParts).') as uniqueParts');

            $items = [];
            $result = $qb->getQuery()->getResult();
            foreach ($result as $row) {
                $items[] = $row['uniqueParts'];
            }
            $uniqueItems = array_unique($items);

            $this->rowCount = count($uniqueItems);
        } elseif (count($groupParts) == 1) {
            $groupPart = $groupParts[0];

            $qb->resetDQLPart('groupBy');
            $qb->select('COUNT(DISTINCT '.$groupPart.')');

            $this->rowCount = $qb->getQuery()->getSingleScalarResult();
        } else {
            // NO GROUP BY
            $countOneFunction = $qb->getEntityManager()
                ->getConfiguration()
                ->getCustomStringFunction('COUNT_ONE');
            if ($countOneFunction !== null) {
                $qb->select('COUNT_ONE() AS rowCount');
            } else {
                $fromPart = $dqlParts['from'];
                $qb->select('COUNT('.$fromPart[0]->getAlias().')');
            }

            $this->rowCount = $qb->getQuery()->getSingleScalarResult();
        }

        return $this->rowCount;
    }
564576
public function get_last_insert_row(){
		$last_insert_info = $this->crud->get_last_insert_info();
		// var_dump($last_insert_info->table_name, $last_insert_info->insert_data);
		$result = $this->crud->select( $last_insert_info->table_name, $last_insert_info->insert_data );
		// var_dump($result);
		if( !is_array($result) || !count($result) ){
			return false;
		}
		return $result[0];
	}
771952
public function countAffected($cursor = null)
    {
        if (!$cursor instanceof \PDOStatement) {
            $cursor = $this->getCursor();
        }

        if (!$cursor) {
            return 0;
        }

        return $cursor->rowCount();
    }
1371264
function Count($where = null) {
		$this->LoadSchema();
		if ($this->UseCache('count')) {
			$cacheid = md5(json_encode($where));

			if ($value = $this->GetCache('count', $cacheid))
				return $value;
		}

		$this->ResetQuery(array(
			'method' => 'count',
			'table' => $this->table,
			'where' => $where,
		));

		$this->Trigger('access', $where);
		if (!$this->continue)
			return 0;

		$this->Trigger('pull', $where);
		if (!$this->continue)
			return 0;

		$this->Trigger('getall', $where);
		if (!$this->continue)
			return 0;

		$this->db->select('COUNT(*) AS count');
		$this->db->from($this->table);
		if ($where = $this->FilterFields($where, 'where'))
			$this->db->where($where);
		$row = $this->db->get()->row_array();
		if (!$this->continue)
			return 0;

		return isset($cacheid) ? $this->SetCache('count', $cacheid, $row['count']) : $row['count'];
	}
135911
private function count()
    {
        if (!$this->withoutTotalResultCount) {
            $qb = $this->cloneQb($this->queryBuilder);
            $this->resetSqlParts($qb, ['select', 'groupBy', 'orderBy'])
                ->setFirstResult(null)
                ->setMaxResults(null)
                ->select(sprintf('COUNT(DISTINCT %s)', $this->aliasDotPrimary()));
            try {
                $this->totalResultCount = $qb->getQuery()->getSingleScalarResult();
            } catch (NonUniqueResultException $e) {
                $this->totalResultCount = 0;
            } catch (\Exception $e) {
                throw new QueryBuilderException($e->getMessage());
            }
        }

        return $this->totalResultCount;
    }
333343
public function rowCount()
    {
        set_error_handler(array($this->_pdooci,"errorHandler"));
        $rows = null;
        try {
            $rows = \oci_num_rows($this->_stmt);
        } catch (\Exception $e) {
            throw new \PDOException($e->getMessage());
        }
        restore_error_handler();
        return $rows;
    }
1350718
public function affectingStatement($query, $bindings = array())
	{
		return $this->run($query, $bindings, function($me, $query, $bindings)
		{
			if ($me->pretending()) return 0;

			// For update or delete statements, we want to get the number of rows affected
			// by the statement and return that back to the developer. We'll first need
			// to execute the statement and then we'll use PDO to fetch the affected.
			$statement = $me->getPdo()->prepare($query);

			$statement->execute($me->prepareBindings($bindings));

			return $statement->rowCount();
		});
	}
680460
public function getPaginationCount()
	{
		list($orders, $this->orders) = array($this->orders, null);

		$columns = $this->columns;

		// Because some database engines may throw errors if we leave the ordering
		// statements on the query, we will "back them up" and remove them from
		// the query. Once we have the count we will put them back onto this.
		$total = $this->count();

		$this->orders = $orders;

		// Once the query is run we need to put the old select columns back on the
		// instance so that the select query will run properly. Otherwise, they
		// will be cleared, then the query will fire with all of the columns.
		$this->columns = $columns;

		return $total;
	}
1188793
public function last_affected_rows( Statement $statement = NULL ) {

		if ( $statement && ! $this->last_statement === $statement )
			return FALSE;

		return $this->last_affected_rows;
	}
549765
public function numRows()
    {
        if( !isset( $this->numRows ) ) {
            $this->numRows = pg_num_rows( $this->resource );
        }
        return $this->numRows;
    }
181764
public function getHits()
    {
        if ($this->hits === null) {
            $this->hits = $this->stmt->rowCount();
        }

        return $this->hits;
    }