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

SublimeText3 English version
Recommended: Win version, supports code prompts!

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

SAP NetWeaver Server Adapter for Eclipse
Integrate Eclipse with SAP NetWeaver application server.

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
Useful JavaScript development tools
