code = -1;...}" statement can be used to determine whether the data exists."/> code = -1;...}" statement can be used to determine whether the data exists.">

Home >PHP Framework >ThinkPHP >How to query if there is data in thinkphp

How to query if there is data in thinkphp

藏色散人
藏色散人Original
2022-12-09 09:17:221478browse

thinkphp查询是否有数据的方法:1、打开相应的tp文件;2、通过“M("gkwh_dictdata");”实例化对象;3、使用“if($list_dictdata !== null) {$obj->code = -1;...}”语句判断数据是否存在即可。

How to query if there is data in thinkphp

本教程操作环境:Windows7系统、ThinkPHP5版、Dell G3电脑。

thinkphp怎么查询是否有数据?

thinkphp mode find()方法查询记录是否存在的方法

代码如下:

       //字符过滤
       $mode = M("gkwh_dictdata"); // 实例化对象
       $where = "data_value = '".trim($_POST["famiMembFana"])."' or data_value = '".trim($_POST["famiMembLana"])."'";
       $list_dictdata = $mode->where($where)->find(); 
 
       //如果记录存在    
       if($list_dictdata !== null) {
          $obj->code = -1;
         
          $msg = "注册信息有非法字符";
       $obj->msg = $msg;
       $obj->data  = $list_dictdata;      
       $obj->count = 0;
       echo json_encode($obj);
       die;
       }

推荐学习:《thinkPHP视频教程

The above is the detailed content of How to query if there is data in thinkphp. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn