0
Notice : Array to string conversion

every time i try to call

call_user_func_array ("mysqli_stmt_bind_param", array_merge (array ($stmt, 
$types),refValues ($params_array)))

$param_array contains the parameter values and the function refValues returns references of this array

as an example if i executes this request insert into table1(column1) values(value1) the value of Column1 will be 'Array'.

I'm not sure what is the problem here some say that the notice means that my array contains an array inside it and some say that the array is not an array and I'm perplexed

This is an example of the code

$_POST["params"] contains types and parameters like that "{type1:value1}{type2:value2}"

    $ps = mysqli_prepare($cn,base64_decode($nq));
    $params = $_POST["params"];
    $params_array = array();
    $types ="";
    while(strlen($params)>0)
    {
    try
    {
        $n1 = strpos($params,"{");
        $n2 = strpos($params,"}");

        $param = substr($params,$n1+1,$n2-($n1+1));

        $param_exploded = explode(":",$param);
        $type = $param_exploded[0];
        $types.=$type;
        echo "$type \n";
        $param_ex = $param_exploded[1];
        echo "$param_ex \n";
        $param_ex = str_replace(array("&bg","&sp","&en"),array("{",":","}"),$param_exploded);
        array_push($params_array,$param_ex);

        if($n2+1>=strlen($params))
            break;
        $params = substr($params,$n2+1);
        }catch(Exception $x)
        {

            break;
        }
    }
    call_user_func_array("mysqli_stmt_bind_param",array_merge(array($ps),array($types),refValues($params_array)));
    mysqli_stmt_execute($ps);

mysqli_close($cn);
Th3Wolf
  • 149
  • 1
  • 10

2 Answers2

0

As you say, maybe some of the data you send has the wrong type. Have you tried to print what array_merge() returns you ? Maybe the arguments aren't passed in the right order.

Anyway, why don't you try to use directly the function, that that you can choose the order in which the arguments are passed ?

Something like this, maybe ?

$aParams = refValues($params_array);
mysqli_stmt_bind_param($ps, $types, ...$aParams);

In case you are not familiar with the splat, ...$aParams explodes the array and substitutes it with every value in it, passing every value of $aParam as an argument to the function, which is certainly how call_user_func_array() proceeds anyway.

Sarkouille
  • 1,275
  • 9
  • 16
  • Good to know ! Since there was no issue, our comments are no more relevant. I will delete mine and advise you to do the same. Besides, if your issue is solved you should take a moment to pick the answer that fits your question the best the that those who land on this page in the future don't waste time. – Sarkouille Aug 24 '17 at 13:19
0

I'm so sorry i always do mistakes in my code and think that it's something else haha.

The error is at this line :

$param_ex = str_replace(array("&bg","&sp","&en"),array("{",":","}"),$param_exploded);

take a look at $param_exploded it should be $param_exploded[1]

$param_ex = str_replace(array("&bg","&sp","&en"),array("{",":","}"),$param_exploded[1]);

I'm so sorry guys :)

Th3Wolf
  • 149
  • 1
  • 10