7
I have a PDO code and I need to convert this code to mysqli, right now I have something like:
$sql = "SELECT * from tabela where nome = ? AND idade = ? AND outro = ?";
$stmt = $core->conn->prepare($sql);
$bindArray = array( $_POST['nome'], $_POST['idade'], $_POST['outro'] );
$stmt->execute($bindArray);
The problem is in $bindArray, in PDO in function run the $bindArray variable and it automatically binds to the array, in mysqli I’m not able.
What may or may not be possible to do the same with mysqli?
As step dynamic parameters in a preparedStatment? and Select in Mysql with an array
– rray
I am aware of these solutions, but I want to know if it is possible to bind as in PDO, without resorting to the use call_user_func_array and the like.
– lazyFox
Today not possible, Mysqli sins in some things and is also good in others.
– rray
I don’t know, but right now what I’m saying is that you’d have to come up with a very complex expression to do that job. Maybe not very complex, but it wouldn’t be simple either. If I have more time available, we’ll see.
– Edilson
@Edilson, Since the API does not provide anything that does this, I would very much like to see your solution without using
call_user_func_array()
. There are technical reasons forexecute()
not receiving an array andbind_param()
only accept references.– rray
Actually it does, but I didn’t say the solution wouldn’t be based on function
call_user_func_array
. Perhaps I misread your comment, but there is still an alternative, laborious and not recommendable form.– Edilson