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. cookieless domain

    概述 什么是cookieless domain?虽然名字中带有cookie,其实完全可以不使用cookie.这只是一种将网页中静态的文本,图片等的域名和主域名相区别开的方法. 主域名难免会使用到coo ...

  2. Hibernate与iBATIS的比较

    1.出身 hibernate 是当前最流行的o/r mapping框架,它出身于sf.net,现在已经成为jboss的一部分了. ibatis 是另外一种优秀的o/r mapping框架,目前属于ap ...

  3. imx:MfgTool

    MfgTool使用方法: MfgTool很妖,写进去的img的名字一定要符合配置文件里面的命名标准. 具体要参见:        MFG_TOOL\Profiles\Linux\OS Firmware ...

  4. c++ primer plus 习题答案(5)

    p333.7 #include<iostream> #include<cstring> #include<cstdlib> using namespace std; ...

  5. CDH 无法查看history log

    1.配置(core-site.xml) <property>  <name>hadoop.http.staticuser.user</name>  <valu ...

  6. SQL Server配置管理WMI问题

       今天在打开数据库的时候,连接不上.一看错误就知道肯定是SQL Server的服务没开启,所以自然而然的去SQL Server配置管理中去打开,但是打开配置管理器的时候出现了下面的错误:      ...

  7. [置顶] How to create Oracle 11g R2 database manually in ASM?

    Step 1: Specify an Instance Identifier (SID) export ORACLE_SID=maomi Step 2: Ensure That the Require ...

  8. Codeforces 116C - Party(dfs)

    n个人,每个人之多有一个上司.“上司”关系具有传递性.求最少将人分成多少组,每组中的每个人的上司或者间接上司都不在该组.拿到题就用树的直径wa了一炮... 正解是有向无环森林的最长路.从每个跟节点df ...

  9. Redis的入门Demo(java)

    java代码部分参考了:http://www.runoob.com/redis/redis-java.html 在java中使用Redis,需要引入Redis驱动,就是jedis-2.1.0.jar, ...

  10. php Smarty详细配置

    1.在Smarty官网下载 路径:https://github.com/smarty-php/smarty/releases 2.把下载下来的Smarty解压出来 3.把解压出来的Smarty里面的l ...