PHP之thinkphp的数据库操作代码段汇总
来源:互联网 发布:阿莫达非尼 淘宝 编辑:程序博客网 时间:2024/06/10 09:25
## 整理ThinkPHP常见数据库操作API
分类
操作
1
import("lib.Page");
$pg = new \Page(20,2);
引用第三方库
2
public function _initialize(){
header("Content-Type:text/html;charset=utf8");
}
设置文档的编码方式,支持中文显示和插入中文
3
$img_path = __DIR__.'\..\..\..\Public\Uploads\task_1';
$handler = opendir($img_path);
while( ($filename = readdir($handler)) != "" ) {}
closedir($handler);
表示当前路径 -> 打开指定的文件夹 -> 读取文件夹中文件名 -> 关闭句柄
4
$download_file = array();
array("gif", "png", "jpg","jpeg")
sizeof($users)
数组定义 -> 数组初始化 -> 数组的长度
5
$users = $user_tb->where(array("name" => $_GET["name"]))->select();
order('id asc') , order('id desc')
limit(1) ,limit(10,25)
field('id,name')
条件filter数据记录 -> 记录递增/递减 -> 限定条目输出 -> 输出记录字段
6
$arr["ret"] = false;
$arr["error"] = "user_name not exist.";
构建hash数组
7
cookie("username",$_GET["name"]);
cookie("username",null);
cookie("username");
加元素到Cookie中 -> 清除Cookie中元素 -> 获取Cookie中元素
8
$this->ajaxReturn ($arr,"JSON");
采用json的格式返回ajax请求
9
$this->redirect("Login");
页面重定向
10
$table = M('bug_table');
$table->create();
$table->title = $_GET['title'];
$table->reporter = cookie("username");
$table->add();
添加数据库记录
11
$this->assign('list',$list);
$this->display();
12
date('Y-m-d H:i:s',time());
获取日期
13
file_exists(__DIR__.'\persons.xml')
$person=simplexml_load_file(__DIR__.'\persons.xml');
文件存在性判断 -> 读取xml文件到记录对象
14
foreach($love as $lv){ $lv }
foreach ($title as $k => $v) { $k为下标,$v为值 }
遍历数组
15
__PUBLIC__ ,__URL__ , __SELF__ ,__DIR__ , ,
16
iconv("UTF-8", "GB2312",$v);
implode(" ",$arr);
将变量$v从UTF-8转为GB2312格式
将数组转换为一个字符串
17
$dat['name'] = $_GET["name"];
$dat['passwd'] = $_GET["passwd"];
$table->where('id=%s',1)->save($dat);
更新数据库记录
18
$table->where("id > %d",$id)->delete();
删除数据库记录
页面尾部输出用于调试
- PHP之thinkphp的数据库操作代码段汇总
- PHP 连数据库代码段
- PHP随记之config(ThinkPHP汇总)
- 第一段利用PHP连接数据库的代码
- C++中操作数据库的几段代码
- ThinkPHP对数据库的操作
- thinkphp 常用数据库的操作
- 几段PHP 数组操作代码
- 适用的php代码段
- C# 数据库操作通用代码段
- thinkphp中的内置操作数据库与mysql中的函数汇总
- 在使用thinkphp框架时,在模板中尽量少使用php代码段,会导致不解析的后果
- thinkphp配置文件数据库段配置
- 代码段汇总
- php的数据库操作之mysqli
- CI数据库操作汇总(PHP)
- php数据库操作类代码
- ThinkPHP的简单CURD操作代码
- UVa548 _输入处理函数写的很好
- 什么是P问题,NP问题和NPC问题?
- C++标准库——iomanip
- 安卓功能代码
- qt_简易记事本_6
- PHP之thinkphp的数据库操作代码段汇总
- SSH框架整合问题
- SQL Server 查询表的记录数(3种方法,推荐第一种)
- IIS7.0 webconfig的urlrewrite
- Android控件之TimePickerDialog
- Linux之tcpdump用法汇总整理
- PHP开发环境搭建以及开发工具IDE介绍
- c# windows服务 一个进程 多个服务的使用
- 走出迷宫(C程序设计进阶第9周)