## phpstudy 安装:
#### 1. 请点击此处下载http://www.phpstudy.net/download.html
#### 2. 根目录:D:\phpStudy\WWW
#### 3. 把TP5框架文件,放到根目录下面,并将文件夹名字重命名为test。

#### 4. 打开浏览器,在地址栏中输入http://localhost/test/public/

#### 5. 了解TP5框架的MVC 三层架构。打开 D:\phpStudy\WWW\test\application\index\controller 下面的index.php;

将index.php中代码改为:
~~~
<?php
namespace app\index\controller;
class Index
{
public function index()
{
return 'hello world';
}
}
?>
~~~
刷新浏览器:出现“hello world”。

#### 6. 新建数据库:数据库名称:test ,新建表:user。

#### 7. 连接数据库:打开D:\phpStudy\WWW\test\application\database.php

修改图中 数据库名、 密码 等选项。(根据个人数据库设定修改)
**新建model层:**
D:\phpStudy\WWW\test\application\index\model\User.php;代码如下:
~~~
<?php
namespace app\index\model;
use think\Model;
class User extends Model
{
}
?>
~~~
**修改D:\phpStudy\WWW\test\application文件夹下的config.php文件:**
false改为true。

~~~
// 控制器类后缀
'controller_suffix' => true,
~~~
**对应的index控制器都加后缀Controller;**
1、文件名由Index.php=>IndexController.php
2、IndexController.php代码修改:
~~~
<?php
namespace app\index\controller;
use think\Controller;
use app\index\model\User;//引用User模板;
class IndexController extends Controller
{
public function index()
{
return 'hello world';
}
}
?>
~~~
**读取数据库数据:**
IndexController.php:
~~~
<?php
namespace app\index\controller;
use think\Controller;
use app\index\model\User;
use think\Db;
class IndexController extends Controller
{
public function index()
{
$sql = new User;
$sqldata = Db::table('User')-> where('Id','>','0')->select();
dump($sqldata) ;
//return $this->fetch();
}
}
?>
~~~
刷新浏览器:

ok,搞定数据库!
下面就开始弄前端的index.html了 ^_^ 。。。