|  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #25544 Only 255 characters returned from varchar field
Submitted: 2003-09-15 09:37 UTC Modified: 2003-09-16 05:35 UTC
From: snick at getart dot ru Assigned: abies
Status: Not a bug Package: MSSQL related
PHP Version: 4.3.2 OS: Windows 2003 Server
Private report: No CVE-ID:
 [2003-09-15 09:37 UTC] snick at getart dot ru
Then I try to read value of VARCHAR field I get only 255 characters, but VARCHAR is 8000 bytes long.

MSSQL v. 7.0
ntwdblib.dll v. 2000.80.194.0
PHP v. 4.3.2
Apache v. 2.0.43 / IIS 6

Reproduce code:
$myVar = str_repeat("*", 500);
mssql_query("DELETE FROM myTable");
mssql_query("INSERT INTO myTable (myField) VALUES ('".$myVar."')");
$query = "SELECT LEN(myField), myField FROM myTable";
list($realLength, $myVar) = mssql_fetch_row(mssql_query($query));
echo "DB length: ".$realLength."; PHP length: ".strlen($myVar);

Expected result:
$myVar must be equal $realLength

Actual result:
strlen($myVar) == 255 (always)


Add a Patch

Pull Requests

Add a Pull Request


AllCommentsChangesGit/SVN commitsRelated reports
 [2003-09-15 18:30 UTC]
Sorry, but your problem does not imply a bug in PHP itself.  For a
list of more appropriate places to ask for help using PHP, please
visit as this bug system is not the
appropriate forum for asking support questions. 

Thank you for your interest in PHP.

You're dealing with VARCHAR maximum length limitation of 255 characters. This is not a PHP bug.
 [2003-09-16 03:55 UTC]
Don't think so ...
He's using Microsoft SQL Server, which has VARCHAR fields of up to 8000 characters (or bytes, not sure)

I'll have a look at this ...
 [2003-09-16 05:35 UTC]

this is probably what you meant in the first place, but I'll elaborate a little more:

MS SQL support on Win32 is implemented using the DbLib C API by Microsoft, which has this limitation. Use TEXT fields instead.
 [2004-01-28 16:56 UTC] php at electricsurfer dot com
There's an easy workaround:
No other changes !
PHP Copyright © 2001-2015 The PHP Group
All rights reserved.
Last updated: Sun Oct 04 07:01:31 2015 UTC