php.net |  support |  documentation |  report a bug |  advanced search |  search howto |  statistics |  random bug |  login
Bug #54435 mssql_bind not working in a loop
Submitted: 2011-03-31 19:36 UTC Modified: 2016-10-15 23:16 UTC
Votes:1
Avg. Score:5.0 ± 0.0
Reproduced:0 of 0 (0.0%)
From: bruce dot amick at bbvany dot com Assigned:
Status: Wont fix Package: MSSQL related
PHP Version: 5.3.6 OS: xp iis
Private report: No CVE-ID: None
Welcome back! If you're the original bug submitter, here's where you can edit the bug or add additional notes.
If you forgot your password, you can retrieve your password here.
Password:
Status:
Package:
Bug Type:
Summary:
From: bruce dot amick at bbvany dot com
New email:
PHP Version: OS:

 

 [2011-03-31 19:36 UTC] bruce dot amick at bbvany dot com
Description:
------------
We migrated an application from Apache/mssql to IIS/mssql.  All scripts, sprocs, etc stayed the same.  Only change was to the database driver.  We have a problem in that the mssql_bind now no longer works in the foreach loop.  The exact same script does work if we explicitly bind each variable.

//this doesn't work:
        $sp_name = "proc_entity_types";
	$paramArray = array();
        $paramArray['mode'] = "V";
        $paramArray['entity_typeId'] = "";
	$paramArray['entity_type'] = "";
	$paramArray['retail_type'] = "";
	$paramArray['document_mapping_type'] = "";
		
        $procRes = mssql_init($sp_name);
        foreach($paramArray as $key=>$value) {                
                $value = trim($value);
		mssql_bind($procRes,"@$key",&$value,SQLVARCHAR);
        }

//this does work(!)
        $procRes = mssql_init("proc_entity_types");
	$mode = "V";
	$entity_typeId = "";
	$retail_type = "";
	$document_mapping_type = "";
	
	 mssql_bind($procRes,"@mode",&$mode,SQLVARCHAR);
	 mssql_bind($procRes,"@entity_typeId",&$entity_typeId,SQLVARCHAR);
	 mssql_bind($procRes,"@entity_type",&$entity_type,SQLVARCHAR);
 	 mssql_bind($procRes,"@retail_type",&$retail_type,SQLVARCHAR);
	 mssql_bind($procRes,"@document_mapping_type",&$document_mapping_type,SQLVARCHAR);
	 
	 $result = mssql_execute($procRes);

//*********/

note: we've tried...
1) mssql_bind($procRes,"@$key",&$value,SQLVARCHAR); 
2) mssql_bind($procRes,'@'.$key,&$value,SQLVARCHAR);
3) mssql_bind($procRes,'@'.$key,$value,SQLVARCHAR);

We've tried while loops instead of foreach... 

And again, it all worked fine in apache connecting to the same db.

Test script:
---------------
        //doesn't work:
        $sp_name = "proc_entity_types";
	$paramArray = array();
        $paramArray['mode'] = "V";
        $paramArray['entity_typeId'] = "";
	$paramArray['entity_type'] = "";
	$paramArray['retail_type'] = "";
	$paramArray['document_mapping_type'] = "";
		
        $procRes = mssql_init($sp_name);
        foreach($paramArray as $key=>$value) {                
                $value = trim($value);
		mssql_bind($procRes,"@$key",&$value,SQLVARCHAR);
        }

       //this does
        $procRes = mssql_init("proc_entity_types");
	$mode = "V";
	$entity_typeId = "";
	$retail_type = "";
	$document_mapping_type = "";
	
	 mssql_bind($procRes,"@mode",&$mode,SQLVARCHAR);
	 mssql_bind($procRes,"@entity_typeId",&$entity_typeId,SQLVARCHAR);
	 mssql_bind($procRes,"@entity_type",&$entity_type,SQLVARCHAR);
 	 mssql_bind($procRes,"@retail_type",&$retail_type,SQLVARCHAR);
	 mssql_bind($procRes,"@document_mapping_type",&$document_mapping_type,SQLVARCHAR);
	 
	 $result = mssql_execute($procRes);


Patches

Pull Requests

History

AllCommentsChangesGit/SVN commitsRelated reports
 [2011-04-06 09:27 UTC] aharvey@php.net
-Package: *Database Functions +Package: MSSQL related
 [2016-10-15 23:16 UTC] kalle@php.net
-Status: Open +Status: Wont fix
 [2016-10-15 23:16 UTC] kalle@php.net
With MSSQL being removed from PHP as of PHP7.0, and ext/mssql not having a maintainer, I'm gonna close this report as a Won't fix, until maybe one day it will find a new maintainer.

Alternatively you can use sqlsrv from Microsoft if you are on Windows, or pdo_dblib if you are on Unix.
 
PHP Copyright © 2001-2025 The PHP Group
All rights reserved.
Last updated: Mon May 12 04:01:29 2025 UTC