コード例 #1
0
ファイル: functions.php プロジェクト: steenhulthin/hult.in
/**
 * Add an option to the DB
 *
 * Pretty much stolen from WordPress
 *
 * @since 1.4
 * @param string $option Name of option to add. Expected to not be SQL-escaped.
 * @param mixed $value Optional option value. Must be serializable if non-scalar. Expected to not be SQL-escaped.
 * @return bool False if option was not added and true otherwise.
 */
function yourls_add_option($name, $value = '')
{
    global $ydb;
    $table = YOURLS_DB_TABLE_OPTIONS;
    $name = trim($name);
    if (empty($name)) {
        return false;
    }
    // Use clone to break object refs -- see commit 09b989d375bac65e692277f61a84fede2fb04ae3
    if (is_object($value)) {
        $value = clone $value;
    }
    $name = yourls_escape($name);
    // Make sure the option doesn't already exist
    if (false !== yourls_get_option($name)) {
        return false;
    }
    $_value = yourls_escape(yourls_maybe_serialize($value));
    yourls_do_action('add_option', $name, $_value);
    $ydb->query("INSERT INTO `{$table}` (`option_name`, `option_value`) VALUES ('{$name}', '{$_value}')");
    $ydb->option[$name] = $value;
    return true;
}
コード例 #2
0
ファイル: functions.php プロジェクト: momoim/momo-api
function yourls_add_option($name, $value = '')
{
    global $ydb;
    $table = YOURLS_DB_TABLE_OPTIONS;
    $safe_name = yourls_escape($name);
    // Make sure the option doesn't already exist. We can check the 'notoptions' cache before we ask for a db query
    if (false !== yourls_get_option($safe_name)) {
        return;
    }
    $_value = yourls_escape(yourls_maybe_serialize($value));
    $ydb->query("INSERT INTO `{$table}` (`option_name`, `option_value`) VALUES ('{$name}', '{$_value}')");
    $ydb->option[$name] = $value;
    return;
}