1

Attempting to create a function to type less code for mssql_bind I wish to use this 2d array:

Array
(
    [0] => Array
        (
            [0] => SIZECODENO
            [1] => SQLVARCHAR
        )
    [1] => Array
        (
            [0] => SIZECODE
            [1] => SQLVARCHAR
        )
    [..] => Array
        (
           .....
        )
)

By using a for loop like so:

for($x=0;$x<count($array);$x++) {
    mssql_bind ($sp,"@".$array[$x][0],$_GET[$array[$x][0]], $array[$x][1]);
}

which returns unsupported type error on all of the mssql_bind commands run by the for loop.

while if I would replace $array[$x][1] to SQLVARCHAR it accepts it right away

Zhorov
  • 28,486
  • 6
  • 27
  • 52
Eugene
  • 17
  • 5

1 Answers1

0

I have resorted to just running it through a switch case. My guess is that it's being seen as a string, and "mssql_bind" doesnt expect string to be there.

Still, I'm hoping there's a better way to do this

for($x=0;$x<count($array);$x++){
    switch($array[$x][1]) {
        case $array[$x][1]=='SQLVARCHAR':
            mssql_bind ($sp,"@".$array[$x][0],$_GET[$array[$x][0]], SQLVARCHAR);
            break;
        case $array[$x][1]=='SQLINT2':
            mssql_bind ($sp,"@".$array[$x][0],$_GET[$array[$x][0]], SQLINT2);
            break;
        case $array[$x][1]=='SQLCHAR':
            mssql_bind ($sp,"@".$array[$x][0],$_GET[$array[$x][0]], SQLCHAR);
            break;
        case $array[$x][1]=='SQLTEXT':
            mssql_bind ($sp,"@".$array[$x][0],$_GET[$array[$x][0]], SQLTEXT);
            break;
        //... more cases that corresponds to datatypes  ...
    }

}
Eugene
  • 17
  • 5