function GetRowCount($strSQL) { global $conn; $strSQL = str_replace(array("\r\n", "\n", "\t"), " ", $strSQL); $tstr = strtoupper($strSQL); $ind1 = strpos($tstr, "SELECT "); $ind2 = my_strrpos($tstr, " FROM "); $ind3 = my_strrpos($tstr, " GROUP BY "); if ($ind3 === false) { $ind3 = strpos($tstr, " ORDER BY "); if ($ind3 === false) { $ind3 = strlen($strSQL); } } $countstr = substr($strSQL, 0, $ind1 + 6) . " count(*) " . substr($strSQL, $ind2 + 1, $ind3 - $ind2); $countrs = db_query($countstr, $conn); $countdata = db_fetch_numarray($countrs); return $countdata[0]; }
/** * Get count of rows from the query * @param String strSQL * @param Connection connection * @return Number * @intellisense */ function GetRowCount($strSQL, $connection) { $strSQL = str_replace(array("\r\n", "\n", "\t"), " ", $strSQL); $tstr = strtoupper($strSQL); $ind1 = strpos($tstr, "SELECT "); $ind2 = my_strrpos($tstr, " FROM "); $ind3 = my_strrpos($tstr, " GROUP BY "); if ($ind3 === false) { $ind3 = strpos($tstr, " ORDER BY "); if ($ind3 === false) { $ind3 = strlen($strSQL); } } $countstr = substr($strSQL, 0, $ind1 + 6) . " count(*) " . substr($strSQL, $ind2 + 1, $ind3 - $ind2); $countdata = $connection->query($countstr)->fetchNumeric(); return $countdata[0]; }