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