| @@ 784-795 (lines=12) @@ | ||
| 781 | * @param string $cond Condition, can be where, having etc, raw sql string. |
|
| 782 | * @return int -1: error/N >= 0: number of rows |
|
| 783 | */ |
|
| 784 | public function GetRowCount ($tbl, $cond = '') { |
|
| 785 | $rs = $this->PExecute($this->GenSql(array( |
|
| 786 | 'SELECT' => array('c' => 'count(1)'), |
|
| 787 | 'FROM' => $tbl, |
|
| 788 | )) . ' ' . $cond); |
|
| 789 | if (false == $rs || 0 != $this->ErrorNo() |
|
| 790 | || 0 == $rs->RowCount()) |
|
| 791 | // Execute error |
|
| 792 | return -1; |
|
| 793 | else |
|
| 794 | return $rs->fields['c']; |
|
| 795 | } // end of func GetRowCount |
|
| 796 | ||
| 797 | ||
| 798 | /** |
|
| @@ 1011-1031 (lines=21) @@ | ||
| 1008 | * @param string $condition Raw sql, can be WHERE, HAVING etc |
|
| 1009 | * @return int |
|
| 1010 | */ |
|
| 1011 | public function getRowCount($table, $condition = '') |
|
| 1012 | { |
|
| 1013 | $sqlCfg = [ |
|
| 1014 | 'SELECT' => ['c' => 'COUNT(1)'], |
|
| 1015 | 'FROM' => $table, |
|
| 1016 | ]; |
|
| 1017 | $rs = $this->executePrepare( |
|
| 1018 | $this->getSqlGenerator()->get($sqlCfg) |
|
| 1019 | . ' ' . $condition |
|
| 1020 | ); |
|
| 1021 | if (false == $rs || 0 != $this->conn->ErrorNo() |
|
| 1022 | || 0 == $rs->RowCount() |
|
| 1023 | ) { |
|
| 1024 | // Execute error, rare happen |
|
| 1025 | // @codeCoverageIgnoreStart |
|
| 1026 | return -1; |
|
| 1027 | // @codeCoverageIgnoreEnd |
|
| 1028 | } else { |
|
| 1029 | return $rs->fields['c']; |
|
| 1030 | } |
|
| 1031 | } |
|
| 1032 | ||
| 1033 | ||
| 1034 | /** |
|