public function mysql($urlInfo) { $d = new Demo(); $d->id = $urlInfo['params'][1]; $d->prop = intval($urlInfo['params'][2]); //新增举例 echo AiMySQL::insert($d) ? "插入成功<br>" : "没有插入<br>"; //修改举例 $d->prop = rand(0, 99999); echo AiMySQL::update($d) ? "修改成功<br>" : "没有修改<br>"; //删除举例 echo AiMySQL::delete($d) ? "删除成功<br>" : "没有删除<br>"; //实体查询举例 $c[] = new AiMySQLCondition('id', '=', "123yfds"); $c[] = new AiMySQLCondition('prop', '=', 60919); //select * from demo where id = "123yfds" and prop = 60919 order by id desc limit 2 , 5 $rs = AiMySQL::queryEntity('Demo', $c, AiMySQLCombination::COMB_AND, 'id', AiMySQLOrderBy::DESC, 5, 2); if (false !== $rs) { foreach ($rs as $demo) { var_dump($demo); echo "<br>"; } } //任意查询举例 $sql = 'select distinct id "主键", count(*) "个数" from fm_demo group by id desc '; $rs = AiMySQL::queryCustom($sql); foreach ($rs as $r) { echo $r['主键'] . ' => ' . $r['个数'] . '<br>'; } }
/** * 根据某个唯一性字段,获取实体 * @invoked 多处调用 * @param string $table 去除前缀的表名 * @param array(AiMySQLCondition) $conditions 筛选条件的集合 * @return BaseEntity mixed 返回目标实体,失败时返回null。 <br> */ static function getEntityFromField($table, $conditions) { $rs = AiMySQL::queryEntity($table, $conditions); $r = null; if ($rs) { foreach ($rs as $r) { } } return $r; }