php - 在 CodeIgniter 3 中使用 PDO 进行查询
问题描述
我只是尝试使用 CI V3.1.9 连接到 MySQL 服务器并检索数据。使用PDO作为驱动怎么样?
如何获取数据?因为我的查询总是返回空格。
这是我的database.php
'dsn' => 'mysql:host=localhost;dbname:db_dms;',
'hostname' => '',
'username' => 'user',
'password' => '123',
'database' => 'db_dms',
'dbdriver' => 'pdo',
'dbprefix' => '',
'pconnect' => TRUE,
'db_debug' => TRUE,
'cache_on' => FALSE,
'cachedir' => '',
'char_set' => 'utf8',
'dbcollat' => 'utf8_general_ci',
'swap_pre' => '',
'encrypt' => FALSE,
'compress' => FALSE,
'stricton' => FALSE,
'failover' => array(),
'save_queries' => TRUE
这是我的controller.php
class Login extends CI_Controller
{
public function index()
{
$data['bError'] = false;
$data['sErrorMessage'] = '';
$this->load->model("ModPengguna");
if(isset($_POST['btnLogin']))
{
$result = $this->db->conn_id->prepare("select * from m_user where userID = ? and pass = ?");
//binding option using PDO
$result->bindValue(1, 'SUPERADM01', PDO::PARAM_STR);
$result->bindValue(2, '123', PDO::PARAM_STR);
$result->execute();
print_r($result->result());
//I also tried this
print_r($result->fetch(PDO::FETCH_ASSOC));
}
}
}
如何获取数据?
谢谢。
解决方案
推荐阅读
- javascript - Reactjs - 我正在尝试在弹出窗口中处理和事件,但在事件执行后弹出窗口没有按应有的方式呈现
- reactjs - reactjs的render方法中的api调用
- java - 想要暂停/恢复抓取特定时间的扫描。使用 Android 抓取 sdk
- android - 如何在自定义 textinputlayout 中修复背景红色
- php - 如何在 Laravel 的 TODO 列表应用程序中执行过期变量?
- windows - 从列表中读取文件名,找到它的计数并将文件名和计数重定向到 windows cmd 中的另一个文件
- docker - 构建映像时如何将 server.xml 复制到 dockerized tomcat
- java - 如何获取用户 ID 以在 android studio 中执行显示列表以供管理员查看订单列表?
- networking - 带有网络策略 + calico 的 GKE 拒绝语句
- linux-kernel - 为嵌入式板编写设备驱动程序