【发布时间】:2013-12-13 21:07:00
【问题描述】:
2 天前,SQL Admin 将 MSSQL 从 2008 升级到 2008 R2。 在此升级之前,我使用 FreeTDS 的 MSSQL,但升级后我无法从存储过程中读取任何输出参数。所以我从 Microsoft Site for Linux 安装了官方 ODBC 驱动程序(我使用的是 CentoOS 64) 现在: 我可以连接,做一个简单的查询,但我无法从存储过程中捕获任何输出参数,也无法捕获查询输出:
select OutputString from tTableOutput where ID = 5
OutputString 包含大型 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 内存?
感谢您的帮助
【问题讨论】:
标签: php sql-server pdo odbc centos