|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2006-09-13 13:06 UTC] gkrajci at arescorporation dot com
Description: ------------ When using PDO to retrieve text from a SQL Server text data type field the text is truncated when I display it on a Web page PDO Transcript length = 4096 (truncated) PEAR Transcript length = 6139(full text) Using SQL Server 2000 Reproduce code: --------------- $sql = "SELECT title AS VideoTitle, transcript_text AS TranscriptText FROM video WHERE video_id = 324"; $dbh = new PDO($pdo_dsn, $db_user, $db_password); $transcript_q = $dbh->query($sql); $transcript_rs = $transcript_q->fetch(); $pear_dsn = "$db_type://$db_user:$db_password@$db_host/$db_name"; require_once( 'DB.php' ); $db = DB::connect( $pear_dsn, true ); if ( DB::isError($db) ) die( $db->getMessage() ); $res = $db->query($sql); $row = $res->fetchRow(); Expected result: ---------------- The text in TranscriptText to be the text and the same length. Actual result: -------------- See Description for this bug report. PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Mon Nov 03 12:00:02 2025 UTC |
ini_set('mssql.textlimit', '65536'); ini_set('mssql.textsize', '65536'); it is work for php_mssql.dll but not work for php_pdo_mssql.dll how can i get more than 4096 byte in TEXT with php_pdo_mssql.dll ???Hello! Have you tried $pdo->query('SET TEXTSIZE {number} '); Where number is text size (in bytes). Max number is 2 GB in bytes.Trying $pdo->query('SET TEXTSIZE {number}'); did not work... $dbh = new PDO($pdo_dsn, $db_user, $db_password); $sql = "SELECT the_content, DATALENGTH(the_content) AS d_l FROM content WHERE content_id = 578"; $dbh->query('SET TEXTSIZE 300000'); $stmt = $dbh->prepare($sql); $stmt->execute(); while ( $row = $stmt->fetch() ) { $video_count++; echo 'LENGTH: '.strlen($row["the_content"]).', '.$row["d_l"].'<br />'; } OUTPUT: LENGTH: 4096, 24868I have done some various testing and to me it still seems that PHP's PDO-class is the problem. The following is the output from my script: Zend Framework - WITHOUT TEXTSIZE 20480 - PHP strlen() : 4096 - MSSQL2005 datalength(): 12418 - WITH TEXTSIZE 20480 - PHP strlen() : 4096 - MSSQL2005 datalength(): 12418 PHP PDO-class - WITHOUT TEXTSIZE 20480 - PHP strlen() : 4096 - MSSQL2005 datalength(): 12418 - WITH TEXTSIZE 20480 - PHP strlen() : 4096 - MSSQL2005 datalength(): 12418 PHP mssql_*() - WITHOUT TEXTSIZE 20480 - PHP strlen() : 12418 - MSSQL2005 datalength(): 12418 Everything fails except PHP's mssql-* functions and I assume that Zend_Db fails because it uses PHP's PDO-class. This test was run with: PHP 5.2.6 (cli) (built: May 2 2008 18:02:07) mssql - MSSQL Support => enabled - Active Persistent Links => 0 - Active Links => 0 - Library version => 7.0 pdo_mssql - PDO Driver for MSSQL DB-lib => enabled - Flavour => MSSQL_70 Zend Framework 1.7.4 (r13879) If needed then the script for the output can be found at http://2p0.dk/phps/test_4096.phpsOn further analysis, it seems SET_TEXTSIZE doesn't work even when you set it explicitly. I have a working fix for this, but no telling when it'll get into CVS as I have to install an entirely new second build environment for PHP 5.3 before I can commit it. The documentation comment still holds, and setting the textsize works for all related extensions except pdo_dblib (AKA pdo_mssql.dll). Best workaround: use PDO_ODBC to connect to MSSQL Server instead. //$dsn = 'mssql:host=MYBOX;dbname=testdb'; $dsn = 'odbc:DRIVER={SQL Server};SERVER=MYBOX;DATABASE=testdb;'; HTH - StephAccording to the SQL Server documenation, SET TEXTSIZE { number } by itself is not sufficient. That's why the original mssql library has two configuration directives: mssql.textlimit and mssql.textsize Since PDO is configured not to use configuration directives, it would be nice if the pdo_mssql driver added two driver_options to configure these values. A quote from SQL Server Books Online: Setting SET TEXTSIZE affects the @@TEXTSIZE function. The DB-Library variable DBTEXTLIMIT also limits the size of text data returned with a SELECT statement. If DBTEXTLIMIT is set to a smaller size than TEXTSIZE, only the amount specified by DBTEXTLIMIT is returned. For more information, see "Programming DB-Library for C" in SQL Server Books Online. The SQL Server ODBC driver and Microsoft OLE DB Provider for SQL Server automatically set TEXTSIZE to 2147483647 when connecting. The setting of set TEXTSIZE is set at execute or run time and not at parse time.Those changes are still in SVN. That means the TEXTLIMIT var is being set to its highest possible value, which in turn means that truncation shouldn't be an issue now. $pdo->query('SET TEXTSIZE 300000'); should work from PHP 5.2.11 up, it just needs doccing.