php - PDO setFetchMode 的 Codeigniter 替代方案

标签 php mysql sql codeigniter pdo

在 Codeigniter 中,如何将数据库查询的结果集提取到模型中?在 native PHP PDO 引擎中,我有类似的东西:

$pdo->setFetchMode(PDO::FETCH_INTO, new className());

所以我有一个类:

class ClassName {
    private $id;
}

我想要的是数据库查询的结果来填充类,所以:

$query = $this->db->get_where("table", array("id" => 1));
$object = $query->row.....(new className());

echo $object->id;
// Shows 1

谢谢 拉杜

最佳答案

如果我没理解错的话,这就是你想要做的。

根据 documentation :

$query = $this->db->get_where('table', array('id' => 1));
$object = $query->row(0, 'Your_Class_name') // Class MUST be loaded prior to use
echo $object->id; // Shows 1

关于php - PDO setFetchMode 的 Codeigniter 替代方案,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19496815/

相关文章:

javascript - 修复当站点移动到子目录时 Assets 的 "/"(根)引用

javascript - 通过 Ajax 的 MYSQL 数据库到 Highcharts 图表

sql - 在 Oracle 中快速生成连接字符串的方法

php - 如何在 Joomla 的给定查询中选择用户名?

PHP 特征 : How to circumvenient constructors or force them to be called?

php - 通知 : Trying to get property of non-object in php

mysql - 从本地文件更新 MySQL 表

mysql - 无法在本地主机 :3306 with user root 连接到 MySQL

mysql - 从命令提示符使用批处理文件运行 sql 脚本

sql - 比较两个表中的两个选择