php 常用的数据库查询方式:

//根据where 条件查询,使用select()方法

访问:http://localhost/thinkphp2/index.php/Machine/search_ip/?ip=192.168.32.101

返回:
array (size=2)
0 =>
array (size=4)
'sn' => string '63' (length=2)
'ip' => string '192.168.32.101' (length=14)
'info' => string 'dr-mysql' (length=8)
'env' => string 'env-backup' (length=10)
1 =>
array (size=4)
'sn' => string '221' (length=3)
'ip' => string '192.168.32.101' (length=14)
'info' => string 'testscan' (length=8)
'env' => string 'aa' (length=2) 控制层程序:
class machineAction extends Action {
public function search_ip(){
$user=M('machine');
//返回数组
//$arr=$user->select();
$where['ip'] = $_GET['ip'];
$Machine = M('Machine_info');
$arr = $Machine->where($where)->select();
dump($arr);
//$this->assign('list',$arr);
$this->show();
}
} //根据where 条件查询,使用find()方法,只返回一条: 访问:
http://localhost/thinkphp2/index.php/Machine/search_ip/?ip=192.168.32.101 只返回一条:
array (size=4)
'sn' => string '63' (length=2)
'ip' => string '192.168.32.101' (length=14)
'info' => string 'dr-mysql' (length=8)
'env' => string 'env-backup' (length=10) 控制层程序:
<?php
// 本类由系统自动生成,仅供测试用途
class machineAction extends Action {
public function search_ip(){
$user=M('machine');
//返回数组
//$arr=$user->select();
$where['ip'] = $_GET['ip'];
$Machine = M('Machine_info');
$arr = $Machine->where($where)->find();
dump($arr);
//$this->assign('list',$arr);
$this->show();
}
} //组查询,然后按ip排序 http://localhost/thinkphp2/index.php/Machine/search_env/env/env-zjtest3 控制层程序: public function search_env(){
$Machine = M('Machine_info');
//返回数组
//$arr=$user->select();
$where['env'] = $_GET['env']; $arr = $Machine->where($where)->order('ip')->select();
dump($arr);
//$this->assign('list',$arr);
$this->show();
} //范围查询 http://localhost/thinkphp2/index.php/Machine/search_range?startip=10&stopip=20 控制层程序: public function search_range(){
$m = M('Machine_info');
//返回数组
//$arr=$user->select();
$startIp = $_GET['startip'];
$stopIp = $_GET['stopip']; $arr = $m->query("select * from machine_info where substring_index(ip,'.',-1)>".$startIp." and substring_index(ip,'.',-1)<".$stopIp);
dump($arr);
//$this->assign('list',$arr);
$this->show();
}
}

thinkphp 常用的查询的更多相关文章

  1. thinkphp where()条件查询

    今天来给大家讲下查询最常用但也是最复杂的where方法,where方法也属于模型类的连贯操作方法之一,主要用于查询和操作条件的设置.where方法的用法是ThinkPHP查询语言的精髓,也是Think ...

  2. ThinkPHP(3)SQL查询语句

    ThinkPHP中对查询语句,包含了基本的查询方式.表达方式.快速查询.区间查询.组合查询.SQL查询.动态查询和子查询. 一.查询方式 ThinkPHP提供了三种基本的查询方式:字符串条件查询.索引 ...

  3. MySQL常用的查询命令

    MySQL常用的查询命令 author: headsen chen   2017-10-19  10:15:25 个人原创.转载请注明作者,出处,否则依法追究法律责任 1,查询现在的时间:mysql& ...

  4. mysql常用快速查询修改操作

    mysql常用快速查询修改操作 一.查找并修改非innodb引擎为innodb引擎 # 通用操作 mysql> select concat('alter table ',table_schema ...

  5. ThinkPHP getBy动态查询

    getBy动态查询 ThinkPHP getBy动态查询是一个魔术方法,可以根据某个字段名称动态得到对应的一条数据记录. 根据用户名(username)查询对应的用户资料记录: public func ...

  6. thinkphp 构建子查询

      thinkphp构建子查询sql语句写法        从3.0版本开始新增了子查询支持,有两种使用方式: 1.使用select方法 当select方法的参数为false的时候,表示不进行查询只是 ...

  7. neo4j 常用命令查询,以及更新 节点 的 label 名 和 property 名

    常用命令查询 https://neo4j.com/docs/cypher-refcard/current/ 更新节点的 labels 有时候 发现节点的 label 名字起错了怎么修改呢?!一个节点是 ...

  8. HTML常用标签查询

    JAVA开发避免不了要接触前端,所以我不得不从0开始学习前端内容!下面分享我自己总结的HTML常用标签查询代码:将下面代码复制粘贴到文本文档,然后另存为html格式;通过file:///文档保存路径的 ...

  9. [转] 常用SQL查询语句

    sunada  的原文地址 常用SQL查询语句 一.简单查询语句 1. 查看表结构 SQL>DESC emp; 2. 查询所有列 SQL>SELECT * FROM emp; 3. 查询指 ...

随机推荐

  1. popupwindow 模拟新浪、腾讯title弹框效果

    .jpg外部引用 原始文档 MainActivity.java外部引用 原始文档 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 ...

  2. 自己定义控件-GifView

    一.描写叙述 显示Gif 的View 原理是用 MediaPlayer 实现的 二.源代码 https://github.com/mentor811/Demo_GifView [ 声明:版权全部,欢迎 ...

  3. Windows API中几个函数的总结

    [DllImport("User32.dll", EntryPoint = "FindWindow")] public static extern IntPtr ...

  4. Uploadif稍做扩展使用

    文章出自Uploadify扩展配置使用http://www.wuyinweb.com/doc/52/57.aspx 在做项目中涉及多文件上传,经过筛选,选择了Uploaidify,但还涉及一个问题,就 ...

  5. iphone手机上的click和touch

    在iphone手机上绑定click事件时,当你触发点击事件时,你绑定的click事件的DOM节点,会自动被一块浮层选中.所以如果使用事件委托来做事件绑定会造成很差的用户体验. 使用touchstart ...

  6. .net 更改日期格式

    示例:更改日期格式 下面的代码示例使用 Regex.Replace 方法将 mm/dd/yy 格式的日期替换为 dd-mm-yy 格式的日期. static string MDYToDMY(strin ...

  7. bzoj 1047 : [HAOI2007]理想的正方形 单调队列dp

    题目链接 1047: [HAOI2007]理想的正方形 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 2369  Solved: 1266[Submi ...

  8. Oracle select into from 和 insert into select

    select into from SQLSERVER  创建表: select * into aaa from bbb Oracle 创建表: create table aaa as select * ...

  9. Node log4js

    一个完善的项目,日志是必不可少的一部分,在node开发中,调试成了让开发者头疼的部分,因此日志成为在node中帮助调试的一个重要模块. 一.Node使用Log4js 1.使用npm工具,在命令行中 执 ...

  10. 首页 导航栏隐藏 下一级页面显示,pop回来遇到的问题

    - (void)viewWillAppear:(BOOL)animated {    [super viewWillAppear:animated];    [self.navigationContr ...