I'm writing an OOP database class for mysqli. I want all queries to be prepared, but I'm having difficulties binding parameters to queries dynamically.
I want the query method API to look like this
query($sql, $param)
However, I don't know how to bind the parameters dynamically within the method. I searched for examples in PHP manual and saw codes like these:
$method = new ReflectionMethod('mysqli_stmt', 'bind_param');
$method->invokeArgs($stmt, $params);
$stmt->execute();
I know the ReflectionMethod() will execute the method for the object or class, but I don't understand how it works in this case, considering that each parameter has a type which should be specified while binding.
How can I bind the parameters dynamically?
Secondly, how does ReflectionMethod() work in this situation?