--TEST-- Test fetching varchar and nvarchar max fields --DESCRIPTION-- Test fetching varchar and nvarchar max fields as streams or strings with or without client buffer --SKIPIF-- --ENV-- PHPT_EXEC=true --FILE-- SQLSRV_CURSOR_CLIENT_BUFFERED)); } else { $stmt = sqlsrv_prepare($conn, $query); } if (!$stmt) { fatalError("runTest ($buffered): failed to prepare select statement"); } if (!sqlsrv_execute($stmt)) { fatalError("runTest ($buffered): failed to execute select"); } if (!sqlsrv_fetch($stmt)) { fatalError("runTest ($buffered): failed to fetch data"); } fetchAsString($stmt, 0, $strValue); fetchAsString($stmt, 1, $nstrValue); if (!sqlsrv_execute($stmt)) { fatalError("runTest ($buffered): failed to execute select"); } if (!sqlsrv_fetch($stmt)) { fatalError("runTest ($buffered): failed to fetch data"); } fetchAsStream($stmt, 0, $strValue); fetchAsStream($stmt, 1, $nstrValue); } function fetchAsString($stmt, $index, $expected) { trace("fetchAsString ($index):\n"); $sqltype = ($index > 0) ? SQLSRV_PHPTYPE_STRING('UTF-8') : SQLSRV_PHPTYPE_STRING(SQLSRV_ENC_CHAR); $value = sqlsrv_get_field($stmt, $index, $sqltype); if (!checkData($value, $expected)) { echo("fetchAsString ($index) expected:\n$expected\nActual:\n$value\n"); } } function fetchAsStream($stmt, $index, $expected) { trace("fetchAsStream ($index):\n"); $sqltype = ($index > 0) ? SQLSRV_PHPTYPE_STREAM('UTF-8') : SQLSRV_PHPTYPE_STREAM(SQLSRV_ENC_CHAR); $stream = sqlsrv_get_field($stmt, $index, $sqltype); if ($stream !== false) { $value = ''; while (!feof($stream)) { $value .= fread($stream, 8192); } fclose($stream); if (!checkData($value, $expected)) { echo("fetchAsStream ($index) expected:\n$expected\nActual:\n$value\n"); } } } function checkData($actual, $expected) { $success = true; $pos = strpos($actual, $expected); if (($pos === false) || ($pos > 1)) { $success = false; } return ($success); } ?> --EXPECT-- Done