thinkphp 3.2 =》0623-7 调用数据库
2015-12-09 14:58
751 查看
1. 控制器=》 shopApplication/Admin/Controller/GoodsController.class.php
public function index(){
// $goodsModel = D('Goods'); //Admin/Model/GoodsModel
// $goodsModel = D('Home/Goods'); //Admin/Model/GoodsModel
// $studentModel = D('student'); //D()方法中的参数对应的模型可以不存在,使用基础模型类创建对象,但是基础模型类还是操作的是参数对应的表
// $model = D();
// $model->query('select * from itcast_goods'); //执行查询类的sql
// $model->execute('delete|update|insert'); //执行修改类的sql
/* $goodsModel = D('Goods'); //如果根据Goods找不到对应的模型, 就直接调用M('Goods')方法
$goodsModel2 = M('Goods');
dump($goodsModel);
dump($goodsModel2);*/
// mysql_query('select *或者是字段 from 表名 where 条件 order by 列名 limit having');
// exit;
/*
$goodsModel->select();//查询
$goodsModel->add();//添加
$goodsModel->save();//修改
$goodsModel->delete();//删除.*/
$goodsModel = D('Goods');
$rows = $goodsModel->select();
// $goodsModel->field('goods_name,goods_price');
// $goodsModel->where('goods_price>1000 and goods_price<2000');
// $goodsModel->group('goods_category_id');
// $goodsModel->order('goods_category_id asc,goods_price desc');
// $goodsModel->limit(2,2);
// $rows = $goodsModel->field('goods_name')->order('goods_price')->where('goods_price>1000 and goods_price<2000')->limit(0,2)->select();
// $rows = $goodsModel->where("goods_id = %d","8")->select();
/* $goodsModel->count('*');
$goodsModel->max('goods_price');*/
// $goodsModel->find(9);
// $rows = $goodsModel->select();//select方法执行查询出数据
// dump($rows);
// exit;
$this->assign('rows',$rows);
$this->display();
}
------------------**********---------------------************-------------------------
2. 模型;=》 shopApplication/Admin/Model/GoodsModel.class.php
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 14-6-23
* Time: 下午2:08
*/
namespace Admin\Model;
use Think\Model;
class GoodsModel extends Model{
/* //配置该模型对应的特有前缀
protected $tablePrefix = 'beijing_';
//修改该模型操作的表名
protected $tableName = 'product';
//直接指定让其操作的表名
protected $trueTableName = 'xxxxxxxxxxx';*/
}
---------******-------------------------------**********-------------------
3. 显示页=》 shopApplication/Admin/View/Goods/index.html
<!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>
<title>ECSHOP 管理中心 - 商品管理 </title>
<meta name="robots" content="noindex, nofollow">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="__CSS__/general.css" rel="stylesheet" type="text/css" />
<link href="__CSS__/main.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>
<span class="action-span"><a href="brandAdd.html">添加货品</a></span>
<span class="action-span1"><a href="#">ECSHOP 管理中心</a></span>
<span id="search_id" class="action-span1"> - 商品 </span>
<div style="clear:both"></div>
</h1>
<div class="form-div">
<form action="" name="searchForm">
<img src="__IMG__/icon_search.gif" width="26" height="22" border="0" alt="search" />
<input type="text" name="brand_name" size="15" />
<input type="submit" value=" 搜索 " class="button" />
</form>
</div>
<form method="post" action="" name="listForm">
<div class="list-div" id="listDiv">
<table cellpadding="3" cellspacing="1">
<tr>
<th>商品名称</th>
<th>商品价格</th>
<th>商品数量</th>
<th>添加时间</th>
<th>更新时间</th>
<th>操作</th>
</tr>
<volist name="rows" id="row" empty="没有记录">
<tr>
<td class="first-cell">
<span style="float:right">{$row.goods_name}</span>
</td>
<td align="center">{$row.goods_price}</td>
<td align="center">{$row.goods_number}</td>
<td align="center">{:date('Y-m-d H:i:s',$row['inputTime'])}</td>
<td align="center">2013-12-17 14:51</td>
<td align="center">
<a href="#" title="编辑">编辑</a> |
<a href="#" title="编辑">移除</a>
</td>
</tr>
</volist>
<tr>
<td align="right" nowrap="true" colspan="6">
<div id="turn-page">
总计 <span id="totalRecords">11</span>
个记录分为 <span id="totalPages">1</span>
页当前第 <span id="pageCurrent">1</span>
页,每页 <input type='text' size='3' id='pageSize' value="15" />
<span id="page-link">
<a href="#">第一页</a>
<a href="#">上一页</a>
<a href="#">下一页</a>
<a href="#">最末页</a>
<select id="gotoPage">
<option value='1'>1</option>
</select>
</span>
</div>
</td>
</tr>
</table>
</div>
</form>
<div id="footer">
共执行 3 个查询,用时 0.021251 秒,Gzip 已禁用,内存占用 2.194 MB<br />
4000
版权所有 © 2005-2012 上海商派网络科技有限公司,并保留所有权利。</div>
</body>
</html>
------------------------------*************-----------------------------***************---------------
4.效果显示图 :
public function index(){
// $goodsModel = D('Goods'); //Admin/Model/GoodsModel
// $goodsModel = D('Home/Goods'); //Admin/Model/GoodsModel
// $studentModel = D('student'); //D()方法中的参数对应的模型可以不存在,使用基础模型类创建对象,但是基础模型类还是操作的是参数对应的表
// $model = D();
// $model->query('select * from itcast_goods'); //执行查询类的sql
// $model->execute('delete|update|insert'); //执行修改类的sql
/* $goodsModel = D('Goods'); //如果根据Goods找不到对应的模型, 就直接调用M('Goods')方法
$goodsModel2 = M('Goods');
dump($goodsModel);
dump($goodsModel2);*/
// mysql_query('select *或者是字段 from 表名 where 条件 order by 列名 limit having');
// exit;
/*
$goodsModel->select();//查询
$goodsModel->add();//添加
$goodsModel->save();//修改
$goodsModel->delete();//删除.*/
$goodsModel = D('Goods');
$rows = $goodsModel->select();
// $goodsModel->field('goods_name,goods_price');
// $goodsModel->where('goods_price>1000 and goods_price<2000');
// $goodsModel->group('goods_category_id');
// $goodsModel->order('goods_category_id asc,goods_price desc');
// $goodsModel->limit(2,2);
// $rows = $goodsModel->field('goods_name')->order('goods_price')->where('goods_price>1000 and goods_price<2000')->limit(0,2)->select();
// $rows = $goodsModel->where("goods_id = %d","8")->select();
/* $goodsModel->count('*');
$goodsModel->max('goods_price');*/
// $goodsModel->find(9);
// $rows = $goodsModel->select();//select方法执行查询出数据
// dump($rows);
// exit;
$this->assign('rows',$rows);
$this->display();
}
------------------**********---------------------************-------------------------
2. 模型;=》 shopApplication/Admin/Model/GoodsModel.class.php
<?php
/**
* Created by PhpStorm.
* User: Administrator
* Date: 14-6-23
* Time: 下午2:08
*/
namespace Admin\Model;
use Think\Model;
class GoodsModel extends Model{
/* //配置该模型对应的特有前缀
protected $tablePrefix = 'beijing_';
//修改该模型操作的表名
protected $tableName = 'product';
//直接指定让其操作的表名
protected $trueTableName = 'xxxxxxxxxxx';*/
}
---------******-------------------------------**********-------------------
3. 显示页=》 shopApplication/Admin/View/Goods/index.html
<!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>
<title>ECSHOP 管理中心 - 商品管理 </title>
<meta name="robots" content="noindex, nofollow">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link href="__CSS__/general.css" rel="stylesheet" type="text/css" />
<link href="__CSS__/main.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h1>
<span class="action-span"><a href="brandAdd.html">添加货品</a></span>
<span class="action-span1"><a href="#">ECSHOP 管理中心</a></span>
<span id="search_id" class="action-span1"> - 商品 </span>
<div style="clear:both"></div>
</h1>
<div class="form-div">
<form action="" name="searchForm">
<img src="__IMG__/icon_search.gif" width="26" height="22" border="0" alt="search" />
<input type="text" name="brand_name" size="15" />
<input type="submit" value=" 搜索 " class="button" />
</form>
</div>
<form method="post" action="" name="listForm">
<div class="list-div" id="listDiv">
<table cellpadding="3" cellspacing="1">
<tr>
<th>商品名称</th>
<th>商品价格</th>
<th>商品数量</th>
<th>添加时间</th>
<th>更新时间</th>
<th>操作</th>
</tr>
<volist name="rows" id="row" empty="没有记录">
<tr>
<td class="first-cell">
<span style="float:right">{$row.goods_name}</span>
</td>
<td align="center">{$row.goods_price}</td>
<td align="center">{$row.goods_number}</td>
<td align="center">{:date('Y-m-d H:i:s',$row['inputTime'])}</td>
<td align="center">2013-12-17 14:51</td>
<td align="center">
<a href="#" title="编辑">编辑</a> |
<a href="#" title="编辑">移除</a>
</td>
</tr>
</volist>
<tr>
<td align="right" nowrap="true" colspan="6">
<div id="turn-page">
总计 <span id="totalRecords">11</span>
个记录分为 <span id="totalPages">1</span>
页当前第 <span id="pageCurrent">1</span>
页,每页 <input type='text' size='3' id='pageSize' value="15" />
<span id="page-link">
<a href="#">第一页</a>
<a href="#">上一页</a>
<a href="#">下一页</a>
<a href="#">最末页</a>
<select id="gotoPage">
<option value='1'>1</option>
</select>
</span>
</div>
</td>
</tr>
</table>
</div>
</form>
<div id="footer">
共执行 3 个查询,用时 0.021251 秒,Gzip 已禁用,内存占用 2.194 MB<br />
4000
版权所有 © 2005-2012 上海商派网络科技有限公司,并保留所有权利。</div>
</body>
</html>
------------------------------*************-----------------------------***************---------------
4.效果显示图 :
相关文章推荐
- thinkphp整合ueditor上传功能
- php自动加载机制
- php7 兼容 mysql
- ubuntu 14.04上源码编译安装php7
- WindowManager.LayoutParams
- thinkphp 关于iis上面中文参数乱码问题
- phpstorm激活
- PHP编程效率的20个要点
- Cygwin下安装SFTP Server
- windows ftp自动上传bat脚本
- PHP php面向对象的入门
- PHP正则表达式
- thinkPHP使用post方式查询时分页失效的解决方法
- 【PHP面向对象(OOP)编程入门教程】4.如何抽象出一个类?
- phpstorm配置Xdebug进行调试PHP教程
- Ubuntu下,ftp启用pam之后报 530 Login incorrect的解决办法
- PHP传值和传引用、传地址的区别
- 学习php设计模式 php实现备忘录模式(Memento)
- Strace 追踪 php 模拟页面执行,打印log
- php中Session的生成机制、回收机制和存储机制探究