对于我的项目,我们使用SQL 2008连接。这非常有效。查询在不给出db或PHP错误的情况下停止运行。这对我来说很奇怪。我做的模型功能是:
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是该公司的名称。
当我直接在SQL db中运行它时,此查询很有效。找到所有联接 并且正确填充选择数据。但是当我在Codeigniter中运行这个查询时 PHP脚本像骰子一样停止工作。
当我查看Codeigniter的核心时,它会在调用此核心函数时停止运行: 系统/数据库/驱动程序/ 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);
}
这是Codeigniter的错误吗?我可以尝试做什么?
P.S。当删除选择的前五行时查询运行良好,但我需要这些字段,并且根据SQL程序连接是oké..
行:
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,
- 编辑 - 我使用GitHub的Codeigniter 2.2最新版本。
答案 0 :(得分:1)
您有两个不同的列别名AS tankvolume
。 MSSQL并不关心(这就是在sqlcmd或ssms中执行时查询工作正常的原因),但PHP确实如此,因为它不知道将哪些值分配给->tankvolume
属性。尝试重命名其中一个。
或者,因为在这种特殊情况下,它是同一列两次,只需删除第二个副本:
leasecar.[Fuel Tank Volume] AS tankvolume,