PHP--TP开发模式
0、開啟調試模式(WWW\tp5\application\config.php)
? ? 'app_debug' =>true,
1、連接數據庫(...database.php)
?????// 數據庫類型
? ? 'type'? ? ? ? ? ? => 'mysql',
? ? // 服務器地址
? ? 'hostname'? ? ? ? => '127.0.0.1',
? ? // 數據庫名
? ? 'database'? ? ? ? => 'testphp',
? ? // 用戶名
? ? 'username'? ? ? ? => 'root',
? ? // 密碼
? ? 'password'? ? ? ? => 'root',
2、控制器中書寫代碼(...application\index\controller\Index.php)
<?php
????namespace app\index\controller;
????//引入系統數據類
????use think\Db;
????//引入系統控制類
????use think\Controller;
????class Index extends Controller
????{
? ? ????public function index()
? ????? {
????//從數據庫中讀取數據
????$data=Db::table('user')->select();
????//分配數據給頁面
????$this->assign('data',$data);
????//加載頁面
????return view();
? ????? }
????}
3、頁面中(...index\view\index\index.html)
????{volist name="data" id="value"}
<tr>
<td>{$value.id}</td>
<td>{$value.name}</td>
<td>{$value.pass}</td>
</tr>
????{/volist}
二:數據庫 增刪改查
<?php namespace app\index\controller; use think\Db; class Index { public function index() { return '<style type="text/css">*{ padding: 0; margin: 0; } .think_default_text{ padding: 4px 48px;} a{color:#2E5CD5;cursor: pointer;text-decoration: none} a:hover{text-decoration:underline; } body{ background: #fff; font-family: "Century Gothic","Microsoft yahei"; color: #333;font-size:18px} h1{ font-size: 100px; font-weight: normal; margin-bottom: 12px; } p{ line-height: 1.6em; font-size: 42px }</style><div style="padding: 24px 48px;"> <h1>:)</h1><p> ThinkPHP V5<br/><span style="font-size:30px">十年磨一劍 - 為API開發設計的高性能框架</span></p><span style="font-size:22px;">[ V5.0 版本由 <a href="http://www.qiniu.com" target="qiniu">七牛云</a> 獨家贊助發布 ]</span></div><script type="text/javascript" src="https://tajs.qq.com/stats?sId=9347272" charset="UTF-8"></script><script type="text/javascript" src="https://e.topthink.com/Public/static/client.js"></script><think id="ad_bd568ce7058a1091"></think>'; } //查詢 public function query(){ $date=Db::Query("select * from user where id=?",[2]); dump($date); echo Db::getLastSql(); } //增 public function insert(){ //$data=Db::execute("insert into user value(null,'user1','321')"); //$data=Db::execute("insert into user value(null,?,?)",['user2','12345']); $data=Db::execute("insert into user value(null,:name,:pass)",['name'=>'user3','pass'=>'12345']); dump($data); } //刪除 public function deletes(){ //$data=Db::execute("delete from user where id=?",[3]); //$data=Db::execute("delete from user where id=2"); $data=Db::execute("delete from user where id=:id",['id'=>8]); dump($data); } //修改 public function update(){ //$data=Db::execute("update user set pass=? where id=?",["888",9]); $data=Db::execute("update user set pass=? where id=?",["666",9]); $data=Db::execute("update user set pass=:pass where id=:id",['pass'=>"555",'id'=>10]); dump($data); } }總結
以上是生活随笔為你收集整理的PHP--TP开发模式的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: EditText 输入类型 androi
- 下一篇: 动态规划算法php,php算法学习之动态