ID: 44325
User updated by: alexr at oplot dot com
Reported By: alexr at oplot dot com
Status: Open
Bug Type: MSSQL related
Operating System: All
PHP Version: 5.2.5
New Comment:
I'm update code :)
replace
if ( (type==SQLVARCHAR) || (type==SQLCHAR) || (type==SQLTEXT) ) {
/*
variable-length type */
if (is_null) {
maxlen=0;
datalen=0;
}
else {
convert_to_string_ex(var);
datalen=Z_STRLEN_PP(var);
value=(LPBYTE)Z_STRVAL_PP(var);
}
}
To
if ( (type==SQLVARCHAR) || (type==SQLCHAR) || (type==SQLTEXT) ) {
/*
variable-length type */
if (is_null) {
maxlen=0;
datalen=0;
}
else {
if( Z_TYPE_PP(var) == IS_NULL ) {
maxlen=0;
datalen=0;
}
else
{
convert_to_string_ex(var);
datalen=Z_STRLEN_PP(var);
value=(LPBYTE)Z_STRVAL_PP(var);
if(!datalen) {
datalen=1;
if( maxlen == -1 ) maxlen=1;
}
}
}
}
Previous Comments:
------------------------------------------------------------------------
[2008-03-04 16:20:00] alexr at oplot dot com
Sorry. This is duplicate of http://bugs.php.net/bug.php?id=40394 bug
with fix :)
Could you please correct my code or approve it?
------------------------------------------------------------------------
[2008-03-04 16:09:27] alexr at oplot dot com
Description:
------------
mssql_bind not correctly bind empty strings as parameter value.
I add in php_mssql.c
if(!datalen) {
datalen = 1;
maxlen = 1;
}
After the
value=(LPBYTE)Z_STRVAL_PP(var);
To fix this problem.
Please add this code to the next PHP realize.
Reproduce code:
---------------
Code 1:
<?php
$cn = mssql_connect($DBSERVER, $DBUSER, $DBPASS);
mssql_select_db($DB, $cn);
$sp = mssql_init("sp_test");
$val = 0;
mssql_bind($sp, "RETVAL", &$val, SQLINT4);
mssql_bind($sp, "@ID", "", SQLVARCHAR, false, 0);
mssql_execute($sp);
mssql_close($cn);
echo $val;
?>
Code 2:
<?php
$cn = mssql_connect($DBSERVER, $DBUSER, $DBPASS);
mssql_select_db($DB, $cn);
$sp = mssql_init("sp_test");
$val = 0;
mssql_bind($sp, "RETVAL", &$val, SQLINT4);
mssql_bind($sp, "@ID", null, SQLVARCHAR, false, 1);
mssql_execute($sp);
mssql_close($cn);
echo $val;
?>
SQL Code
CREATE PROCEDURE sp_test
@ID varchar(255) null
AS
begin
if @ID is NULL return 2
else return 3
END
Expected result:
----------------
1) "3"
2) "2"
Actual result:
--------------
1) "2"
2) "2"
------------------------------------------------------------------------
--
Edit this bug report at http://bugs.php.net/?id=44325&edit=1