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元

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver Mac version
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

WebStorm Mac version
Useful JavaScript development tools