本文整理汇总了PHP中SQL::current方法的典型用法代码示例。如果您正苦于以下问题:PHP SQL::current方法的具体用法?PHP SQL::current怎么用?PHP SQL::current使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SQL
的用法示例。
在下文中一共展示了SQL::current方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: uninstallCategorize
static function uninstallCategorize()
{
if ($confirm) {
SQL::current()->query("DROP TABLE __categorize");
SQL::current()->delete("post_attributes", "name = 'category_id'");
}
}
示例2: add_signature_updated_at
function add_signature_updated_at()
{
if (!SQL::current()->query("SELECT signature FROM __comments")) {
echo __("Adding signature column to comments table...", "comments") . test(SQL::current()->query("ALTER TABLE __comments ADD signature VARCHAR(32) DEFAULT '' AFTER status"));
}
if (!SQL::current()->query("SELECT updated_at FROM __comments")) {
echo __("Adding updated_at column to comments table...", "comments") . test(SQL::current()->query("ALTER TABLE __comments ADD updated_at DATETIME DEFAULT '0000-00-00 00:00:00' AFTER created_at"));
}
}
示例3: __uninstall
static function __uninstall($confirm)
{
if ($confirm) {
foreach (Attachment::find() as $attachment) {
@unlink(uploaded($attachment->path, true));
}
SQL::current()->query("DROP TABLE __attachments");
}
}
示例4: defaultTo
/**
* Bind the default datasource to another named connection
* @param string $name The datasource name
* @return bool `true` if correctly changed
*/
public static function defaultTo($name)
{
if (isset(self::$connections[$name])) {
self::$current = $name;
return true;
} else {
return false;
}
}
示例5: __uninstall
static function __uninstall($confirm)
{
if ($confirm) {
SQL::current()->query("DROP TABLE __milestones");
SQL::current()->query("DROP TABLE __tickets");
SQL::current()->query("DROP TABLE __revisions");
}
Group::remove_permission("add_milestone");
Group::remove_permission("add_ticket");
Group::remove_permission("add_revision");
Group::remove_permission("edit_milestone");
Group::remove_permission("edit_ticket");
Group::remove_permission("edit_revision");
Group::remove_permission("edit_own_ticket");
Group::remove_permission("edit_own_revision");
Group::remove_permission("delete_milestone");
Group::remove_permission("delete_ticket");
Group::remove_permission("delete_revision");
Group::remove_permission("delete_own_ticket");
Group::remove_permission("delete_own_revision");
Group::remove_permission("code_in_revisions");
}
示例6: notify
/**
* Function: notify
* Emails everyone that wants to be notified for a new comment
*
* Parameters:
* $author - The new comment author
* $body - The new comment message
* $post - The new comment post ID
*/
static function notify($author, $body, $post)
{
$post = new Post($post);
$emails = SQL::current()->select("comments", "author_email", array("notify" => 1, "post_id" => $post->id))->fetchAll();
$list = array();
foreach ($emails as $email) {
$list[] = $email["author_email"];
}
$config = Config::current();
$to = implode(", ", $list);
$subject = $config->name . __("New Comment");
$message = __("There is a new comment at ") . $post->url() . "\n Poster: " . fix($author) . "\n Message: " . fix($body);
$headers = "From:" . $config->email . "\r\n" . "Reply-To:" . $config->email . "\r\n" . "X-Mailer: PHP/" . phpversion();
$sent = email($to, $subject, $message, $headers);
}
示例7: error
$sql = SQL::current(true);
if ($sql->connect(true) and !empty($config->url) and $sql->count("users")) {
error(__("Already Installed"), __("Chyrp is already correctly installed and configured."));
}
}
if (!is_writable(MAIN_DIR) and !file_exists(MAIN_DIR . "/.htaccess") or file_exists(MAIN_DIR . "/.htaccess") and !is_writable(MAIN_DIR . "/.htaccess") and !$htaccess_has_chyrp) {
$errors[] = _f("STOP! Before you go any further, you must create a .htaccess file in Chyrp's install directory and put this in it:\n<pre>%s</pre>", array(fix($htaccess)));
}
if (!is_writable(INCLUDES_DIR)) {
$errors[] = __("Chyrp's includes directory is not writable by the server. In order for the installer to generate your configuration files, please CHMOD or CHOWN it so that Chyrp can write to it.");
}
if (!empty($_POST)) {
if ($_POST['adapter'] == "sqlite" and !@is_writable(dirname($_POST['database']))) {
$errors[] = __("SQLite database file could not be created. Please make sure your server has write permissions to the location for the database.");
} else {
$sql = SQL::current(array("host" => $_POST['host'], "username" => $_POST['username'], "password" => $_POST['password'], "database" => $_POST['database'], "prefix" => $_POST['prefix'], "adapter" => $_POST['adapter']));
if (!$sql->connect(true)) {
$errors[] = _f("Could not connect to the specified database:\n<pre>%s</pre>", array($sql->error));
} elseif ($_POST['adapter'] == "pgsql") {
new Query($sql, "CREATE FUNCTION year(timestamp) RETURNS double precision AS 'select extract(year from \$1);' LANGUAGE SQL IMMUTABLE RETURNS NULL ON NULL INPUT");
new Query($sql, "CREATE FUNCTION month(timestamp) RETURNS double precision AS 'select extract(month from \$1);' LANGUAGE SQL IMMUTABLE RETURNS NULL ON NULL INPUT");
new Query($sql, "CREATE FUNCTION day(timestamp) RETURNS double precision AS 'select extract(day from \$1);' LANGUAGE SQL IMMUTABLE RETURNS NULL ON NULL INPUT");
new Query($sql, "CREATE FUNCTION hour(timestamp) RETURNS double precision AS 'select extract(hour from \$1);' LANGUAGE SQL IMMUTABLE RETURNS NULL ON NULL INPUT");
new Query($sql, "CREATE FUNCTION minute(timestamp) RETURNS double precision AS 'select extract(minute from \$1);' LANGUAGE SQL IMMUTABLE RETURNS NULL ON NULL INPUT");
new Query($sql, "CREATE FUNCTION second(timestamp) RETURNS double precision AS 'select extract(second from \$1);' LANGUAGE SQL IMMUTABLE RETURNS NULL ON NULL INPUT");
}
}
if (empty($_POST['name'])) {
$errors[] = __("Please enter a name for your website.");
}
if (!isset($_POST['timezone'])) {
示例8: safecol
/**
* Function: safecol
* Wraps a column in proper escaping if it is a SQL keyword.
*
* Doesn't check every keyword, just the common/sensible ones.
*
* ...Okay, it only does two. "order" and "group".
*
* Parameters:
* $name - Name of the column.
*/
public static function safecol($name)
{
$lower = strtolower($name);
if ($lower === "order" or $lower === "group") {
return SQL::current()->adapter == "mysql" ? "`" . $name . "`" : '"' . $name . '"';
} else {
return $name;
}
}
示例9: set_error_handler
# <Feather>
require_once INCLUDES_DIR . "/interface/Feather.php";
# Set the error handler to exit on error if this is being run from the tester.
if (TESTER) {
set_error_handler("error_panicker");
}
# Redirect to the installer if there is no config.
if (!file_exists(INCLUDES_DIR . "/config.yaml.php")) {
redirect("install.php");
}
# Start the timer that keeps track of Chyrp's load time.
timer_start();
# Load the config settings.
$config = Config::current();
# Prepare the SQL interface.
$sql = SQL::current();
# Set the timezone for date(), etc.
set_timezone($config->timezone);
# Initialize connection to SQL server.
$sql->connect();
# Sanitize all input depending on magic_quotes_gpc's enabled status.
sanitize_input($_GET);
sanitize_input($_POST);
sanitize_input($_COOKIE);
sanitize_input($_REQUEST);
# Begin the session.
session();
# Set the locale for gettext.
set_locale($config->locale);
# Load the translation engine.
load_translator("chyrp", INCLUDES_DIR . "/locale/" . $config->locale . ".mo");
示例10: destroy
/**
* Function: delete
* Deletes a given object. Calls the @delete_(model)@ trigger with the objects ID.
*
* Parameters:
* $model - The model name.
* $id - The ID of the object to delete.
*/
protected static function destroy($model, $id)
{
$model = strtolower($model);
if (Trigger::current()->exists("delete_" . $model)) {
Trigger::current()->call("delete_" . $model, new $model($id));
}
SQL::current()->delete(pluralize($model), array("id" => $id));
}
示例11: keywords
/**
* Function: keywords
* Handle keyword-searching.
*
* Parameters:
* $query - The query to parse.
* $plain - WHERE syntax to search for non-keyword queries.
* $table - If specified, the keywords will be checked against this table's columns for validity.
*
* Returns:
* An array containing the "WHERE" queries and the corresponding parameters.
*/
function keywords($query, $plain, $table = null)
{
if (!trim($query)) {
return array(array(), array());
}
$search = array();
$matches = array();
$where = array();
$params = array();
if ($table) {
$columns = SQL::current()->select($table)->fetch();
}
$queries = explode(" ", $query);
foreach ($queries as $query) {
if (!preg_match("/([a-z0-9_]+):(.+)/", $query)) {
$search[] = $query;
} else {
$matches[] = $query;
}
}
$times = array("year", "month", "day", "hour", "minute", "second");
foreach ($matches as $match) {
list($test, $equals, ) = explode(":", $match);
if ($equals[0] == '"') {
if (substr($equals, -1) != '"') {
foreach ($search as $index => $part) {
$equals .= " " . $part;
unset($search[$index]);
if (substr($part, -1) == '"') {
break;
}
}
}
$equals = ltrim(trim($equals, '"'), '"');
}
if (in_array($test, $times)) {
if ($equals == "today") {
$where["created_at like"] = date("%Y-m-d %");
} elseif ($equals == "yesterday") {
$where["created_at like"] = date("%Y-m-d %", now("-1 day"));
} elseif ($equals == "tomorrow") {
error(__("Error"), "Unfortunately our flux capacitor is currently having issues. Try again yesterday.");
} else {
$where[strtoupper($test) . "(created_at)"] = $equals;
}
} elseif ($test == "author") {
$user = new User(array("login" => $equals));
if ($user->no_results and $equals == "me") {
$where["user_id"] = Visitor::current()->id;
} else {
$where["user_id"] = $user->id;
}
} elseif ($test == "group") {
$group = new Group(array("name" => $equals));
$test = "group_id";
$equals = $group->no_results ? 0 : $group->id;
} else {
$where[$test] = $equals;
}
}
if ($table) {
foreach ($where as $col => $val) {
if (!isset($columns[$col])) {
if ($table == "posts") {
$where["post_attributes.name"] = $col;
$where["post_attributes.value like"] = "%" . $val . "%";
}
unset($where[$col]);
}
}
}
if (!empty($search)) {
$where[] = $plain;
$params[":query"] = "%" . join(" ", $search) . "%";
}
$keywords = array($where, $params);
Trigger::current()->filter($keywords, "keyword_search", $query, $plain);
return $keywords;
}
示例12: post_latest_comment_attr
public function post_latest_comment_attr($attr, $post)
{
if (isset($this->latest_comments)) {
return fallback($this->latest_comments[$post->id], null);
}
$times = SQL::current()->select("comments", array("MAX(created_at) AS latest", "post_id"), array("status not" => "spam", "status != 'denied' OR (\n (\n user_id != 0 AND\n user_id = :visitor_id\n ) OR (\n id IN " . self::visitor_comments() . "\n )\n )"), null, array(":visitor_id" => Visitor::current()->id), null, null, "post_id");
foreach ($times->fetchAll() as $row) {
$this->latest_comments[$row["post_id"]] = $row["latest"];
}
return fallback($this->latest_comments[$post->id], null);
}
示例13: delete_posts
function delete_posts($aggregate_name)
{
$sql = SQL::current();
$attrs = $sql->select("post_attributes", "post_id", array("name" => "aggregate", "value" => $aggregate_name))->fetchAll();
foreach ($attrs as $attr) {
Post::delete($attr["post_id"]);
}
}
示例14: update_user_password_column
/**
* Function: update_user_password_column
* Updates the @password@ column on the "users" table to have a length of 60.
*
* Versions: 2.0rc3 => 2.0
*/
function update_user_password_column()
{
$sql = SQL::current();
if (!($column = $sql->query("SHOW COLUMNS FROM __users WHERE Field = 'password'"))) {
return;
}
if ($column->fetchObject()->Type == "varchar(60)") {
return;
}
echo __("Updating `password` column on `users` table...") . "\n";
echo " - " . __("Backing up `users` table...") . test($backup = $sql->select("users"));
if (!$backup) {
return;
}
$backups = $backup->fetchAll();
echo " - " . __("Dropping `users` table...") . test($drop = $sql->query("DROP TABLE __users"));
if (!$drop) {
return;
}
echo " - " . __("Creating `users` table...") . test($create = $sql->query("CREATE TABLE IF NOT EXISTS `__users` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n `login` varchar(64) DEFAULT '',\n `password` varchar(60) DEFAULT NULL,\n `full_name` varchar(250) DEFAULT '',\n `email` varchar(128) DEFAULT '',\n `website` varchar(128) DEFAULT '',\n `group_id` int(11) DEFAULT '0',\n `joined_at` datetime DEFAULT '0000-00-00 00:00:00',\n PRIMARY KEY (`id`),\n UNIQUE KEY `login` (`login`)\n ) DEFAULT CHARSET=utf8"));
if (!$create) {
echo " -" . test(false, _f("Backup written to %s.", array("./_users.bak.txt")));
return file_put_contents("./_users.bak.txt", var_export($backups, true));
}
foreach ($backups as $backup) {
echo " - " . _f("Restoring user #%d...", array($backup["id"])) . test($insert = $sql->insert("users", $backup), _f("Backup written to %s.", array("./_users.bak.txt")));
if (!$insert) {
return file_put_contents("./_users.bak.txt", var_export($backups, true));
}
}
echo " -" . test(true);
}
示例15: safecol
/**
* Function: safecol
* Wraps a column in proper escaping if it is a SQL keyword.
*
* Doesn't check every keyword, just the common/sensible ones.
*
* ...Okay, it only does two. "order" and "group".
*
* Parameters:
* $name - Name of the column.
*/
public static function safecol($name)
{
return preg_replace("/(([^a-zA-Z0-9_]|^)(order|group)([^a-zA-Z0-9_]|\n\$))/i", SQL::current()->adapter == "mysql" ? "\\2`\\3`\n\\4" : '\\2"\\3"\\4', $name);
}