function smarty_function_getall($params, &$smarty)
{
    if (!isset($params['from'])) {
        echo 'No table name!';
        return false;
    }
    if (!isset($params['_name'])) {
        echo 'No record variable name!';
        return false;
    }
    global $php;
    $select = new Swoole\SelectDB($php->db);
    $select->call_by = 'func';
    if (!isset($params['order'])) {
        $params['order'] = 'id desc';
    }
    $select->put($params);
    if (isset($params['page'])) {
        $select->paging();
        $pager = $select->pager;
        $smarty->assign("pager", array('total' => $pager->total, 'render' => $pager->render()));
    }
    $records = $select->getall();
    $smarty->_tpl_vars[$params['_name']] = $records;
}
function smarty_block_select($params, $body, &$smarty)
{
    if (is_null($body)) {
        return;
    }
    global $php;
    $select = new Swoole\SelectDB($php->db);
    $select->put($params);
    return SwooleTemplate::parse_loop($select->getall(), $body);
}
function smarty_function_getone($params, &$smarty)
{
    $record_name = $params['_name'];
    if (!array_key_exists($record_name, $smarty->_tpl_vars) or array_key_exists('_force', $params)) {
        global $php;
        $select = new Swoole\SelectDB($php->db);
        $select->call_by = 'func';
        $select->put($params);
        $record = $select->getone();
        $smarty->_tpl_vars[$record_name] = $record;
    }
    //if(array_key_exists('_field',$params)) return $smarty->_tpl_vars[$record_name][$params['_field']];
}
Exemple #4
0
<?php

define('DEBUG', 'on');
define('WEBPATH', realpath(__DIR__ . '/..'));
//包含框架入口文件
require WEBPATH . '/libs/lib_config.php';
$sdb = new \Swoole\SelectDB(Swoole::$php->db);
$sdb->from('userinfo');
$sdb->where('name="rango"');
$sdb->update(['lastlogin_ip' => 2]);
$res = $sdb->rowCount();
var_dump($res);
//$result = $sdb->getall();
//var_dump($result);