[英]How to use database codeigniter class without codeIgniter MVC framework?
My goal is to use the CodeIgniter database Class, but inside a plain PHP script. 我的目标是使用CodeIgniter数据库类,但在一个普通的PHP脚本中。 I don't want to use MVC structure for this.
我不想为此使用MVC结构。
Can I use this database class WITHOUT using the CodeIgniter MVC pattern? 我可以在不使用CodeIgniter MVC模式的情况下使用此数据库类吗?
If yes, how? 如果有,怎么样?
Please follow below steps to integrate Codeigniter DB Active Record 请按照以下步骤集成Codeigniter DB Active Record
Copy below files 复制下面的文件
application/config/config.php application/config/database.php system/database/* system/core/Common.php system/core/Exceptions.php system/core/Log.php
The directory structure is as above 目录结构如上
application/config/database.php
application/config/database.php
添加数据库连接详细信息 Create db connection(connector.php) file 创建数据库连接(connector.php)文件
<?php defined('DS') OR define('DS', DIRECTORY_SEPARATOR); defined('EXT') OR define('EXT', '.php'); defined('ENVIRONMENT') OR define('ENVIRONMENT', 'development'); $dir_path = dirname(__FILE__) . DS; defined('BASEPATH') OR define('BASEPATH', $dir_path . 'system' . DS); defined('APPPATH') OR define('APPPATH', $dir_path . 'application' . DS); function getDBConnector(){ include_once(BASEPATH . "core/Common.php"); include_once(BASEPATH . "core/Exceptions.php"); require_once(BASEPATH . 'database/DB' . EXT); $conn = & DB(); return $conn; } $db = getDBConnector(); print_r($db->get('users')->result_array());
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.