CodeIgniter Forums

Full Version: Not caching multiple resulsets from SQL Server
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

Hello everyone,

I've been using the cache functionality in a current system I'm developing and I think is amazing. But I realized that one query is not being cached, I think is because that special query returns multiple resulsets.

The next code is the code in my model I used to handle this:

public function cifras($indicador = NULL, $jurisdiccion = NULL) {

        $reportes = $this->load->database('database', TRUE);
        $serverName = $reportes->hostname;
        $connectionInfo = array("UID"=> $reportes->username, "PWD" => $reportes->password, "Database"=> $reportes->database);
        $conn = sqlsrv_connect( $serverName, $connectionInfo);
        sqlsrv_configure("WarningsReturnAsErrors", 0);

        if ($conn) {
            $sql = "EXEC [Reporte Concentrado de Reafiliacion 2014]";
            $r = sqlsrv_query($conn, $sql, null);
            if ($r === false) {

            $i = 0;
            $resultsets = array();
            do {
               while ($row = sqlsrv_fetch_object($r)) {
                   if (!empty($jurisdiccion) and isset($row->Jurisdiccion)) {
                       $jurisdiccion_db = $row->Jurisdiccion;
                       if ($jurisdiccion === $jurisdiccion_db) {
                           $resultsets[$i][] = $row;
                   } else {
                       $resultsets[$i][] = $row;
            } while (sqlsrv_next_result($r));
            return (object)$resultsets;  
        } else {
            die(print_r(sqlsrv_errors(), true));

I'd really appreciate if you can help me to solve this.

Thank you very much.