2

For my project we use an SQL 2008 connection. This works very well til now. The query stops running without giving a db or PHP error. It is very strange to me. The model function I've made is:

function getTankDataByYear($year,$flexxis_tabel){                   

    $querytext = "
    SELECT  
        deduction.[Taxation code] AS deduction,
        costkindfuel.[Fuel Type] AS fueltype,
        leasecar.[Fuel Tank Volume] AS tankvolume,          
        leasecardriver.[License] AS kenteken,                                   
        leasecardriver.[Driver Code] AS personeelsnummer,       
        fuel.[Perpetration Date] AS dates,
        fuel.[Perpetration Time] AS times,
        fuel.[Perpetration Date] AS tankdatum,
        fuel.[Volume liters] AS liters,
        fuel.[License No_] AS pk1,
        fuel.[Perpetration Date] AS pk2,
        fuel.[Perpetration Time] AS pk3,        
        fuel.[Costkind lease company] AS pk4,
        fuel.[KM Reliable] AS kmreliable,
        fuel.[Replacement Transport] AS vervangendvervoer,
        fuel.[High Way] AS snelweg
    FROM [".$flexxis_tabel."\$Fuel Table] AS fuel                                                                   
    LEFT JOIN [".$flexxis_tabel."\$Lease Car Driver] AS leasecardriver ON leasecardriver.[License] = fuel.[License No_]
    LEFT JOIN [".$flexxis_tabel."\$Lease Car] AS leasecar ON leasecar.[License No_] = leasecardriver.[License]
    LEFT JOIN [Costkind Fuel] AS costkindfuel ON costkindfuel.[Costkind Fuel] = fuel.[Costkind lease company]
    LEFT JOIN [".$flexxis_tabel."\$Deduction table] AS deduction ON deduction.[Driver code] = leasecardriver.[Driver Code]
        AND (YEAR(Deduction.[Ending Date]) >= '".$year."' 
        OR YEAR(Deduction.[Ending Date]) = '1753')
        AND YEAR(Deduction.[Starting Date]) <= '".$year."'      
    WHERE YEAR(fuel.[Perpetration Date]) = '".$year."'
    ";

    $query = $this->db->query($querytext)->result();
    return $query;
}   

$flexxis_tabel is the name of the company.

This query works well when i run it directly in the SQL db. All joins are found and the select data is filled right. But when i run exactly this query in Codeigniter the PHP script stops working like an die.

When i look at the core of Codeigniter it stops running when calling this core function: system/database/drivers/mssql_result.php

/**
 * Result - object
 *
 * Returns the result set as an object
 *
 * @access  private
 * @return  object
 */
function _fetch_object()
{
    return mssql_fetch_object($this->result_id);
}

Is this an Codeigniter bug? And what can i try to do?

P.S. when removing the first five lines of the select the query runs well, but i need those fields and the joins are oké according the SQL program..

Lines:

    leasecar.[Fuel Tank Volume] AS tankvolume,  
    deduction.[Taxation code] AS deduction,
    costkindfuel.[Fuel Type] AS fueltype,
    leasecar.[Fuel Tank Volume] AS tankvolume,          
    leasecardriver.[License] AS kenteken,                                   
    leasecardriver.[Driver Code] AS personeelsnummer,   

-- Edit -- Iam using Codeigniter 2.2 newest version from GitHub.

JelleP
  • 976
  • 7
  • 20
  • 39
  • Is there anything useful in the [codeigniter error log](http://stackoverflow.com/questions/3209807/how-to-do-error-logging-in-codeigniter-php)? – Dan Sep 02 '14 at 13:53
  • No, sorry. Codeigniter log stays empty.. – JelleP Sep 02 '14 at 14:44
  • Hi @JelleP have you found the answer yet? Because I'm having the same problem too. – Marsha Aug 03 '16 at 02:42

1 Answers1

1

You've got two different columns aliased AS tankvolume. MSSQL doesn't care (which is why the query works fine when executed in sqlcmd or ssms), but PHP does because it doesn't know which of those values to assign to the ->tankvolume property. Try renaming one of them.

Or, since in this particular case, it's the same column twice, just remove the second copy of this:

 leasecar.[Fuel Tank Volume] AS tankvolume, 
Dan
  • 4,312
  • 16
  • 28
  • Hey Dan, Thanks for your idea! But is does not help in my case. I removed the double one, but the query still stops running.. – JelleP Sep 02 '14 at 13:48