Home > php教程 > php手册 > 万能单条件查询函数

万能单条件查询函数

WBOY
Release: 2016-06-07 11:45:23
Original
1086 people have browsed it

万能单条件查询函数,如代码。
函数Getx2x有四个参数:
第一个参数[必须]为表名;
第二个参数[必须]为字段名;
第三个参数[必须]为所查询字段的值。
第四个参数[可选]为所查询的字段名,未填默认为'id'。

//例子1:
//要查询think_user表中,id=12的用户名:
$username=Getx2x('User','username','12');
//或
$username=Getx2x('User','username','12','id');
注:此时$u
函数代码请放于位于项目目录下Common/Common.php中//万能单条件查询函数,由lisan制作<br>     function Getx2x($table,$fields,$id,$str){<br>         $aa=M($table);<br>         if(empty($str)){<br>             $expression='getByid';<br>         }else{<br>             $expression='getBy'.$str;<br>         }<br>         $thisaa=$aa->field($fields)->$expression($id);<br> <br>         $bb=explode(',',$fields);<br>         if(count($bb)             return $thisaa[$fields];<br>         }else{<br>             return $thisaa;<br>         }        <br>     }

AD:真正免费,域名+虚机+企业邮箱=0元

source:php.cn
Statement of this Website
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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template