search
Homephp教程php手册Model修改之添加getOne函数

Model修改之添加getOne函数:只查询一条数据
Model中有find获取一条数据,但是只能用于本身的模型
Model中有query函数根据sql查询一个列表,但是对于只查询一条数据来说,有些不方便,所以重新写了一个只查询一条数据库的函数:    /**<br>      * SQL查询(只取一条数据)<br>      * @access public<br>      * @param string $sql  SQL指令<br>      * @param mixed $parse  是否需要解析SQL<br>      * @return mixed<br>      */<br>     public function getOne($sql,$parse=false) {<br>         if(!is_bool($parse) && !is_array($parse)) {<br>             $parse = func_get_args();<br>             array_shift($parse);<br>         }<br>         if (!preg_match("/LIMIT/i", $sql)) {<br>             $sql = preg_replace('/[,;]$/i', '', trim($sql)) . ' LIMIT 1;';<br>         }<br>         $sql  =   $this->parseSql($sql,$parse);<br>         $resultSet = $this->db->query($sql);<br>         if(false === $resultSet) {<br>             return false;<br>         }<br>         if(empty($resultSet)) {<br>             return null;<br>         }<br>         return $resultSet[0];<br>     }

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

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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

PhpStorm Mac version

PhpStorm Mac version

The latest (2018.2.1) professional PHP integrated development tool

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools