简体   繁体   中英

CENTOS PHP PDO ODBC MSSQL 2008 r2

2 days ago, SQL Admin made upgrade of MSSQL from 2008 to 2008 R2. Before this upgrade,I worked with MSSQL by FreeTDS, but after upgrade I couldn't read any output parameter from stored procedures. So I installed official ODBC driver from Microsoft Site for Linux (I'm using CentoOS 64) Now: I can connect, make a simple query, but I can't catch any output parameter from stored procedure and also I can't catch query output:

select OutputString from tTableOutput where ID = 5 

where OuptutString contain large xml.

I try PDO, ODBC and all not working. If I use PDO:

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

I get:

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 )

How can increase length limit ?

If I use 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);

I get:

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

Why this query need 4GB of memory ?

I would appreciate for any help

I would guess (A driver manager trace might show more) that the driver is describing the result column as a blob/clob/var(max) type and it will be returning a length of either 4Gb or maybe -1. If PHP is deciding to attempt to allocate that much it will fail as you see. I would say its a flaw in PHP. You could try converting the XML column into a TEXT type, that might convince PHP its a longdata type and not to try and save it in one chunk. In the Easysoft driver we added a flag to limit the reported size of long types to avoid this, but thats not much help with the MS driver.

You can try to cast the value as varchar(size of your choice).

ie Change the line:

select OutputString from tTableOutput where ID = 5 

to

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

This will prevent the query to report a size of 4GB.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM