php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #26996 If a field is empty it returns one blank space character.
Submitted: 2004-01-21 12:57 UTC Modified: 2004-01-26 06:06 UTC
From: arion_ at msn dot com Assigned:
Status: Not a bug Package: MSSQL related
PHP Version: 4.3.4 OS: Windows
Private report: No CVE-ID:
 [2004-01-21 12:57 UTC] arion_ at msn dot com
Description:
------------
If a field is empty it returns one blank space character.

Reproduce code:
---------------
<?php
$host="XXX";
$usuario="User";
$password="Password";
$bbdd="BBDD";
$conexion=mssql_connect("$host","$usuario","$password");

$qry="SELECT  Field
	FROM  dbo.Table";
$handle=mssql_query($qry);
$registro=mssql_fetch_row($handle);
$Nothing=$registro[0];
echo "Just" .$Nothing. "DoIt";
?>

Expected result:
----------------
JustDoIt

Actual result:
--------------
Just DoIt

Patches

Add a Patch

Pull Requests

Add a Pull Request

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2004-01-21 14:37 UTC] arion_ at msn dot com
I've just done and I'm sorry :( but 4.3.5RC2-dev doesn't work yet. If you need I test something more, just tell me.

Thanks.

Running on Apache 2.0.48
 [2004-01-21 14:43 UTC] sniper@php.net
Please do not submit the same bug more than once. An existing
bug report already describes this very problem. Even if you feel
that your issue is somewhat different, the resolution is likely
to be the same. 

Thank you for your interest in PHP.

See bug #25777 and add your comments there.

 [2004-01-26 06:06 UTC] arion_ at msn dot com
I've read the bug report you sent me but..... I only need to know if there will be solution in future versions, if I must adapt all my scripts using trim(), or to use 4.3.3 for ever.
Thanks.
 [2004-04-23 15:57 UTC] cbunk at arescorporation dot com
The bug is not bogus and not already covered in bug report http://bugs.php.net/bug.php?id=25777.  The mentioned bug report was fixed causing this specific problem.  When querying a MSSQL db and the field's value is empty a space gets returned, not an empty string as expected.  This is causing lots off problems with scripts I have that check to see if a value is empty to determine if to display some stuff.  The bug report http://bugs.php.net/bug.php?id=26996 got listed as bogus but it was a correct report.  I'm not sure I think I may try submitting another bug report in hopes it will be noticed.
 [2004-05-26 09:36 UTC] marco at alphasoft dot ch
I think this is a bug anyway.
CodeSample 1:
<?php
$db=mssql_connect('myserver','sa','sa');
mssql_select_db('mydb',$db);

//$sql = "DROP TABLE dbtest";
//$res=mssql_query($sql,$db);

$sql = "CREATE TABLE dbtest (id int NOT NULL,abc varchar(20),PRIMARY KEY (id))";
$res=mssql_query($sql,$db);

$sql = "INSERT INTO dbtest (id,abc) VALUES (1,'')";
$res=mssql_query($sql,$db);

$sql = "SELECT abc as xy from dbtest WHERE id=1";
$res=mssql_query($sql,$db);
$d = mssql_fetch_object($res);
mssql_close($db);

echo 'o'.$d->xy.'o';
?>

Expected Output:
oo
Actual Output:
o o

CodeSample 2:
<?php
$db=mssql_connect('myserver','sa','sa');
mssql_select_db('mydb',$db);

//$sql = "DROP TABLE dbtest";
//$res=mssql_query($sql,$db);

$sql = "CREATE TABLE dbtest (id int NOT NULL,abc varchar(20),PRIMARY KEY (id))";
$res=mssql_query($sql,$db);

$sql = "INSERT INTO dbtest (id,abc) VALUES (1,'')";
$res=mssql_query($sql,$db);

$sql = "SELECT 'x'+abc as xy from dbtest WHERE id=1";
$res=mssql_query($sql,$db);
$d = mssql_fetch_object($res);
mssql_close($db);

echo 'o'.$d->xy.'o';
?>

Expected Output:
oxo
Actual Output:
oxo

I find the following example interesting:
CodeSample 3:
<?php
$db=mssql_connect('myserver','sa','sa');
mssql_select_db('mydb',$db);

//$sql = "DROP TABLE dbtest";
//$res=mssql_query($sql,$db);

$sql = "CREATE TABLE dbtest (id int NOT NULL,abc varchar(20),PRIMARY KEY (id))";
$res=mssql_query($sql,$db);

$sql = "INSERT INTO dbtest (id,abc) VALUES (1,'')";
$res=mssql_query($sql,$db);

$sql = "SELECT len(abc) as abclen,abc as xy from dbtest WHERE id=1";
$res=mssql_query($sql,$db);
$d = mssql_fetch_object($res);
mssql_close($db);

echo $d->abclen;
?>

Expected Output:
0
Actual Output:
0


I have tested with php 4.3.6, 4.3.7-dev and 5.0.0RC3-dev on Windows Server 2003 with MSSQL 2000.

Well, is this a bug or a bogus? I think this is a bug!

Greetings
Marco
 [2004-06-03 13:34 UTC] berni at starsucker dot net
Reading trough the MSDN Library it becomes clear, that MS DBLib cannot tell any difference between SELECT '' and SELECT ' '. dbdatalen() will return 1 in both cases because returning 0 would mean SELECT NULL.

This Bug is not Bogus, but technically, it doesn't belog to PHP!

Anyway! I'm suffering WITH you. Me too, I have a big fat project upgraded to php-4.3.4;

Anyway: The Bug #25777 was not properly solved! It was a fix for a very special concern by one person while it changed the behaviour of the complete extension for all PHP Developers. Additionally, by exponating the MS Bug described above, this fix cannot be activated by default. (Make it a PHP Option or whatever...)

I see Bug #25777 in state CLOSED. Well to me, this is as closed as the minds of the PHP Inventors...
 
PHP Copyright © 2001-2014 The PHP Group
All rights reserved.
Last updated: Thu Apr 24 02:02:10 2014 UTC