#40394 [NEW]: mssql_bind() converts empty strings to null

From: Date: Wed, 07 Feb 2007 22:36:19 +0000
Subject: #40394 [NEW]: mssql_bind() converts empty strings to null
Groups: php.bugs 
Request: Send a blank email to php-bugs+get-108561@lists.php.net to get a copy of this message
From:             rnerovich at gmail dot com
Operating system: XP/2003 server
PHP version:      5.2.0
PHP Bug Type:     MSSQL related
Bug description:  mssql_bind() converts empty strings to null

Description:
------------
When using mssql_bind() to pass an empty string to a stored procedure, the
empty string is converted to NULL.  This problem has been reported by
others, but either closed or marked as BOGUS, which is not the case, as
I've reproduced this on both development and deployed systems.

Reproduce code:
---------------
CREATE PROCEDURE REC_PROC_INSERT_MS_INTF
	@UCODE UNIQUEIDENTIFIER, @PHONE VARCHAR(10), @ACCOUNT VARCHAR(25), @EALOC
VARCHAR(38), @TIME DATETIME,
	@RECID UNIQUEIDENTIFIER, @PRBSTR VARCHAR(30)
AS
SELECT @UCODE as ucode, @PHONE as phone, 
	@ACCOUNT as account, @EALOC as ealoc, 
	@TIME as time,
	@RECID as recid, @PRBSTR as prbstr
RETURN 1
GO

$sp = mssql_init('REC_PROC_INSERT_MS_INTF',$dblink->dbresource);
        mssql_bind($sp,"RETVAL",&$rc,SQLINT4,TRUE,TRUE,4);
       
mssql_bind($sp,"@UCODE",$ucode,SQLVARCHAR,FALSE,FALSE,strlen($ucode));
        mssql_bind($sp,"@PHONE",$phone,SQLVARCHAR,FALSE,FALSE,10);
        mssql_bind($sp,"@ACCOUNT",$account,SQLVARCHAR,FALSE,FALSE,25);
        mssql_bind($sp,"@EALOC",$ealoc,SQLVARCHAR,FALSE,FALSE,38);
       
mssql_bind($sp,"@TIME",$currtime,SQLVARCHAR,FALSE,FALSE,strlen($currtime));
       
mssql_bind($sp,"@RECID",$recId,SQLVARCHAR,FALSE,FALSE,strlen($recId));
        mssql_bind($sp,"@PRBSTR",$problem,SQLVARCHAR,FALSE,FALSE,30);
        $result = mssql_execute($sp);
        if($result){
            $row = mssql_fetch_array($result);
            global $log;
            $log->Writelog(var_export($row,true));
        }



Expected result:
----------------
I would expect the empty strings to stay empty.  This causes major
problems with NON-NULLABLE SQL fields!!!

array (
  0 => 'ükÁ#ðÌæM†TèÇS±í°',
  'ucode' => 'ükÁ#ðÌæM†TèÇS±í°',
  1 => '',
  'phone' => '',
  2 => '',
  'account' => '',
  3 => '423998059-130628001',
  'ealoc' => '423998059-130628001',
  4 => '2007-02-07 16:20:54',
  'time' => '2007-02-07 16:20:54',
  5 => 'g÷r}Q\'N°¥@Iñ*¬',
  'recid' => 'g÷r}Q\'N°¥@Iñ*¬',
  6 => '',
  'prbstr' => '',
)

Actual result:
--------------
when any of the strings (not uniqueidentifiers) are set to an empty string
($phone = '') the following is received from the var_export()

array (
  0 => 'ükÁ#ðÌæM†TèÇS±í°',
  'ucode' => 'ükÁ#ðÌæM†TèÇS±í°',
  1 => NULL,
  'phone' => NULL,
  2 => NULL,
  'account' => NULL,
  3 => '423998059-130628001',
  'ealoc' => '423998059-130628001',
  4 => '2007-02-07 16:20:04',
  'time' => '2007-02-07 16:20:04',
  5 => 'g÷r}Q\'N°¥@Iñ*¬',
  'recid' => 'g÷r}Q\'N°¥@Iñ*¬',
  6 => NULL,
  'prbstr' => NULL,
)
the GUIDS look like garbage, but are correct.  The strings however are all
NULL if they were sent in as ''

This is what var_export() reports if all strings are set to ' ' (one
space)

array (
  0 => 'ükÁ#ðÌæM†TèÇS±í°',
  'ucode' => 'ükÁ#ðÌæM†TèÇS±í°',
  1 => ' ',
  'phone' => ' ',
  2 => ' ',
  'account' => ' ',
  3 => '423998059-130628001',
  'ealoc' => '423998059-130628001',
  4 => '2007-02-07 16:20:54',
  'time' => '2007-02-07 16:20:54',
  5 => 'g÷r}Q\'N°¥@Iñ*¬',
  'recid' => 'g÷r}Q\'N°¥@Iñ*¬',
  6 => ' ',
  'prbstr' => ' ',
)




-- 
Edit bug report at http://bugs.php.net/?id=40394&edit=1
-- 
Try a CVS snapshot (PHP 4.4): http://bugs.php.net/fix.php?id=40394&r=trysnapshot44
Try a CVS snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=40394&r=trysnapshot52
Try a CVS snapshot (PHP 6.0): http://bugs.php.net/fix.php?id=40394&r=trysnapshot60
Fixed in CVS:                 http://bugs.php.net/fix.php?id=40394&r=fixedcvs
Fixed in release:             http://bugs.php.net/fix.php?id=40394&r=alreadyfixed
Need backtrace:               http://bugs.php.net/fix.php?id=40394&r=needtrace
Need Reproduce Script:        http://bugs.php.net/fix.php?id=40394&r=needscript
Try newer version:            http://bugs.php.net/fix.php?id=40394&r=oldversion
Not developer issue:          http://bugs.php.net/fix.php?id=40394&r=support
Expected behavior:            http://bugs.php.net/fix.php?id=40394&r=notwrong
Not enough info:              http://bugs.php.net/fix.php?id=40394&r=notenoughinfo
Submitted twice:              http://bugs.php.net/fix.php?id=40394&r=submittedtwice
register_globals:             http://bugs.php.net/fix.php?id=40394&r=globals
PHP 3 support discontinued:   http://bugs.php.net/fix.php?id=40394&r=php3
Daylight Savings:             http://bugs.php.net/fix.php?id=40394&r=dst
IIS Stability:                http://bugs.php.net/fix.php?id=40394&r=isapi
Install GNU Sed:              http://bugs.php.net/fix.php?id=40394&r=gnused
Floating point limitations:   http://bugs.php.net/fix.php?id=40394&r=float
No Zend Extensions:           http://bugs.php.net/fix.php?id=40394&r=nozend
MySQL Configuration Error:    http://bugs.php.net/fix.php?id=40394&r=mysqlcfg


Thread (8 messages)

« previous php.bugs (#108561) next »