php.net |  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 (profile)
Status: Not a bug Package: MSSQL related
PHP Version: 4.3.2 OS: Windows 2003 Server
Private report: No CVE-ID: None
View Add Comment Developer Edit
Anyone can comment on a bug. Have a simpler test case? Does it work for you on a different platform? Let us know!
Just going to say 'Me too!'? Don't clutter the database with that please !
Your email address:
MUST BE VALID
Solve the problem:
40 - 26 = ?
Subscribe to this entry?

 
 [2003-09-15 09:37 UTC] snick at getart dot ru
Description:
------------
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)

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2003-09-15 18:30 UTC] iliaa@php.net
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 http://www.php.net/support.php 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] abies@php.net
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] abies@php.net
Ilia, 

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:
SELECT CAST(F AS TEXT) AS F FROM ...
No other changes !
 
PHP Copyright © 2001-2024 The PHP Group
All rights reserved.
Last updated: Fri Apr 19 04:01:28 2024 UTC