一 代码
1、创建数据库以及数据表
![](https://i-blog.csdnimg.cn/blog_migrate/84e0a6c9f13b9d0bc1175c0cdc67df4e.png)
2、载入ThinkPHP系统文件,编辑入口文件index.php
<?php
define('APP_DEBUG',true);
define('THINK_PATH', '../ThinkPHP/');// 定义ThinkPHP框架路径
define('APP_NAME', '2');//定义项目名称和路径
define('APP_PATH', '.');//定义项目名称和路径
require(THINK_PATH."/ThinkPHP.php");// 加载框架入口文件
//App::run();//实例化一个网站应用实例
?>
3、编译生成的配置文件,完成数据库的配置,config.php,该文件位于D:\AppServ\www\test\30\2\.Home\Conf目录下。
<?php
return array(
'DB_TYPE'=> 'mysql', // 数据库类型
'DB_HOST'=> 'localhost', // 数据库服务器地址
'DB_NAME'=>'db_database30', // 数据库名称
'DB_USER'=>'root', // 数据库用户名
'DB_PWD'=>'root', // 数据库密码
'DB_PORT'=>'3306', // 数据库端口
'DB_PREFIX'=>'think_', // 数据表前缀
);
?>
4、编辑控制器文件,该文件命名为IndexController.class.php,位于D:\AppServ\www\test\30\2\.Home\Controller目录下
<?php
// 本类由系统自动生成,仅供测试用途
namespace Home\Controller;
use Think\Controller;
use Think\Model;
class IndexController extends Controller {
public function index() {
$db = new Model('user'); // 实例化模型类,参数数据表名称,不包含前缀
$select = $db->select(); // 查询数据
$this->assign('select',$select); // 模板变量赋值
$this->display(); // 输出模板
}
}
5、编辑视图文件index.html,该文件位于D:\AppServ\www\test\30\2\.Home\View\Index目录下
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>ThinkPHP开发流程</title>
</head>
<body>
<!--循环输出查询结果数据集-->
<volist name='select' id='user' >
ID:{$user.id}<br/>
用户名:{$user.user}<br/>
地址:{$user.address}<hr>
</volist>
</body>
</html>
二 运行结果
![](https://i-blog.csdnimg.cn/blog_migrate/88b544ccb7f944157f35b0bf041f9335.png)