开发文档 v2.x

单个值(getValue)

更新时间:2024年9月26日 08:24 浏览:440

普通查询

$db = Be::getDb(); 

$sql = 'SELECT name FROM user WHERE id = \'40801a44-9e19-11ec-a3cb-0242ac180065\'';
$name = $db->getValue($sql);

$sql = 'SELECT COUNT(*) FROM user WHERE age<18 AND sex=\'女\'';
$count = $db->getValue($sql);

$sql = 'SELECT MIN(age) FROM user WHERE sex=\'女\'';
$minAge = $db->getValue($sql);

 

占位符查询

$db = Be::getDb(); 

$sql = 'SELECT COUNT(*) FROM user WHERE age<? AND sex=?';
$count = $db->getValue($sql, [18, '女']);

 

返回一个值

  • 当查询结果有多条时,仅取第一条记录
  • 当前询结结有多列时,仅取第一列内容

 

导航