2013-11-28 154 views
0

2天前,SQL Admin將MSSQL從2008升級到2008 R2。 在此升級之前,我使用FreeTDS的MSSQL工作,但升級後無法讀取存儲過程中的任何輸出參數。所以我安裝了官方的ODBC驅動程序從微軟站點的Linux(我使用的是CentoOS 64) 現在: 我可以連接,做一個簡單的查詢,但我不能捕獲存儲過程的任何輸出參數,也不能catch查詢輸出:CENTOS PHP PDO ODBC MSSQL 2008 r2

select OutputString from tTableOutput where ID = 5 

其中OuptutString包含大的xml。

我嘗試PDO,ODBC和所有不工作。 如果我使用PDO:

$result = $db->query("select OutputString from tTableOutput with(nolock) where ID = 5"); 
foreach ($result as $row) { 
    print_r($row); 
} 

我得到:

PHP Fatal error: Uncaught exception 'PDOException' with message 'SQLSTATE[01004]: String data, right truncated: 0 [Microsoft][ODBC Driver 11 for SQL Server]String data, right truncation (SQLFetchScroll[0] at /builddir/build/BUILD/php-5.3.3/ext/pdo_odbc/odbc_stmt.c:528

怎樣才能增加長度的限制?

如果我使用ODBC:

$conn = odbc_connect($dataSource,$user,$password); 
$sql = "select OutputString from tTableOutput where ID = 5"; 

$rs=odbc_exec($conn,$sql); 
odbc_binmode ($rs, ODBC_BINMODE_PASSTHRU); 
odbc_longreadlen ($rs, 0); 

if (!$rs){ 
    exit("Error in SQL"); 
} 
while (odbc_fetch_row($rs)){ 
    print_r(odbc_result($rs, "OutputString")); 

} 
odbc_close($conn); 

我得到:

PHP Fatal error: Allowed memory size of 536870912 bytes exhausted (tried to allocate 4294967293 bytes) 

爲什麼這個查詢需要4GB內存?

我將不勝感激任何幫助

回答

0

我猜(驅動程序管理器跟蹤可能會顯示更多)驅動程序描述結果列作爲BLOB/CLOB/VAR(最大值)類型,它會被返回長度可以是4Gb或者可以是-1。如果PHP決定嘗試分配這麼多,它會失敗,因爲你看到。我會說它在PHP中的一個缺陷。您可以嘗試將XML列轉換爲TEXT類型,這可能說服PHP使用longdata類型,而不是嘗試將其保存在一個塊中。在Easysoft驅動程序中,我們添加了一個標誌來限制長類型的報告大小以避免這種情況,但這對MS驅動程序沒有多大幫助。

0

您可以嘗試將值轉換爲varchar(您選擇的大小)。

即 更改行:

select OutputString from tTableOutput where ID = 5 

select cast(OutputString as varchar(255)) from tTableOutput where ID = 5 

這將阻止查詢報告大小爲4GB。