php 绑定(bind)结果

标签 php mysql

我有这样的代码序列:

$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/

相关文章:

php - Sql Update 字段值相互

php - Laravel 5.1 - 合并多个 Eloquent 查询并按时间戳排序

php - SQL最流行

php - 循环遍历mysql数据库

php - mysql通过不返回左表中的所有结果来左连接和分组

php - 在行之间插入值

php - 上传图像的 zip 文件夹,然后使用 php 将它们转换为缩略图

PHP - 动态页面计数器增量

php - 在 PHP 类中获取数组长度

php - 选择数据时自动更新数据