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. ostringstream的使用方法

    ostringstream的使用方法 [本文来自]http://www.builder.com.cn/2003/0304/83250.shtml http://www.cppblog.com/alan ...

  2. android 视频播放器的INTENT-FILTER属性

    <intent-filter>                   <action android:name="android.intent.action.VIEW&quo ...

  3. js 时间戳转换成时间格式,可自定义格式

    由于 c# 通过ajax获取的时间 传到前台 格式为:/Date(1354116249000)/ 所以需要转换一下,想要什么格式 更改 format() 里的 返回语句 就可以了 formatDate ...

  4. zoj 2110

    这道题困扰我的不是算法问题.而是细节问题.不优化一直搜到底 时间是690ms左右 没有优化的dfs #include<stdio.h> #include<string.h> # ...

  5. WPF多线程下载文件,有进度条

    //打开对话框选择文件         private void OpenDialogBox_Click(object sender, RoutedEventArgs e)         {     ...

  6. Redis的入门Demo(java)

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

  7. MySql 数据库定时备份

    1.使用sqldump+任务计划 mysqldump备份成sql文件==============假想环境:MySQL   安装位置:C:\MySQL论坛数据库名称为:bbsMySQL root   密 ...

  8. c风格字符串函数

    十一.C 风格字符串  1)字符串操作  strcpy(p, p1) 复制字符串  strncpy(p, p1, n) 复制指定长度字符串  strcat(p, p1) 附加字符串  strncat( ...

  9. C语言(1)--准备

    经过很长一段时间的准备,终于重新弄懂了一些C语言的问题,再次熟悉了C语言的大致应用,对此略有体会,在此以博客记录于此! 准备工作: 运行平台:Linux 编辑工具:vim (还可以使用emac,ged ...

  10. Core 发布至Linux

    ASP.NET Core 发布至Linux生产环境 Ubuntu 系统 ASP.NET Core 发布至Linux生产环境 Ubuntu 系统,之前跟大家讲解了 dotnet publish 发布,而 ...