Example #1
0
function s_db_one($sql)
{
    if (s_bad_string($sql, $sql, true) || false === ($link = s_db_slink())) {
        return false;
    }
    if (defined("APP_DB_PREFIX") && ($count = substr_count($sql, '%s_'))) {
        //替换表名:"%s_user:update" => "201204disney_user:update"
        $sql = str_replace('%s_', APP_DB_PREFIX . '_', $sql, $count);
    }
    if (false === ($reader = mysql_query($sql, $link))) {
        die(s_log(mysql_error()));
    }
    // 得到资源后,取得对应的数据
    $row = mysql_fetch_assoc($reader);
    // 释放资源文件
    mysql_free_result($reader);
    s_db_close($link);
    return current($row);
}
Example #2
0
function s_db_one($sql, $prefix = true)
{
    if (s_bad_string($sql) || false === ($db = s_db_slink())) {
        return false;
    }
    if (defined("APP_DB_PREFIX") && ($count = substr_count($sql, '%s_'))) {
        //替换表名:"%s_user:update" => "201204disney_user:update"
        $sql = str_replace('%s_', APP_DB_PREFIX . '_', $sql, $count);
    }
    $ret = $db->queryOne($sql);
    s_db_close($db);
    if (PEAR::isError($ret)) {
        s_error($ret->getMessage());
        $ret = false;
    }
    return empty($ret) ? false : $ret;
}
Example #3
0
function s_db_one($sql, $prefix = true)
{
    if (s_bad_string($sql) || false === ($db = s_db_slink())) {
        return false;
    }
    if ($prefix === true) {
        $sql = _s_db_prefix($sql);
    }
    $ret = $db->queryOne($sql);
    s_db_close($db);
    if (PEAR::isError($ret)) {
        s_err_sql($ret->getMessage());
        $ret = false;
    }
    return $ret;
}