我有这样的代码序列:
$connection = new mysqli('localhost','root','','db-name');
$query = "SELECT * from users where Id = ?";
$stmt = $connection->prepare($query);
$stmt->bind_param("i",$id);
$stmt->execute();
$stmt->bind_result($this->id,$this->cols);
$stmt->fetch();
$stmt->close();
$connection->close();
问题是“SELECT”可能会给出可变数量的列,我将其保留在 $this->cols 中。是否有可能将 bind_result 与可变数量的参数一起使用?...或解决方案的任何替代方案。
最佳答案
如果您有幸运行 PHP 5.3+,mysqli_get_result似乎是你想要的。
$stmt->execute();
$result = $stmt->get_result();
$row = $result->fetch_array();
关于php 绑定(bind)结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9431381/