本文整理汇总了PHP中Db::close_connection方法的典型用法代码示例。如果您正苦于以下问题:PHP Db::close_connection方法的具体用法?PHP Db::close_connection怎么用?PHP Db::close_connection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Db
的用法示例。
在下文中一共展示了Db::close_connection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index
function index()
{
$conn = Db::get_connection();
if (isset($_GET['software_name'])) {
$software_factory = new Software();
$softwares = $software_factory->find_all(array('where_clause' => "`name` = '{$conn->escape($_GET['software_name'])}' AND (`name` != 'guidatv' OR `type` = 'macosx')", 'limit' => 1));
if (count($softwares) > 0) {
$this->software = $softwares[0];
$this->software->has_many('software_releases');
// Sort releases
$releases = $this->software->software_releases;
usort($releases, array($releases[0], 'sort_releases'));
$this->software->release = $releases[0];
$this->software->release->has_many('software_artifacts');
// Horrible hack to enable per-software caching.
$_REQUEST['id'] = $this->software->id;
}
} else {
if (isset($_GET['id'])) {
$this->software = new Software();
$this->software->find_by_id($_GET['id']);
$this->software->has_many('software_releases');
// Sort releases
$releases = $this->software->software_releases;
usort($releases, array($releases[0], 'sort_releases'));
$this->software->release = $releases[0];
$this->software->release->has_many('software_artifacts');
} else {
$this->render_error();
}
}
Db::close_connection($conn);
}
示例2: close_connection
protected function close_connection()
{
if (isset($this->conn)) {
Db::close_connection($this->conn);
unset($this->conn);
}
}
示例3: quantita_history
public static function quantita_history($isin, $username, $month_from)
{
$conn = Db::get_connection();
$transaction_factory = new Transaction();
$transactions = $transaction_factory->find_all(array('where_clause' => "`utente` = '{$conn->escape($username)}' " . "AND `isin` = '{$conn->escape($isin)}' " . "AND `data` >= '{$conn->escape($month_from)}' ", 'order_by' => '`data` DESC'));
// print_r($transactions);
$portfolio_stock_factory = new PortfolioStock();
$portfolio_stock = $portfolio_stock_factory->find_all(array('where_clause' => "`utente` = '{$conn->escape($username)}' " . "AND `isin` = '{$conn->escape($isin)}' "))[0];
// print_r($portfolio_stock);
$quantita_history = array();
$quantita_history[date('Y-m-d')] = $q = $portfolio_stock->quantita;
$i = 0;
do {
if ($transactions[$i]->azione == 'acquisto') {
$q -= $transactions[$i]->quantita;
} else {
$q += $transactions[$i]->quantita;
}
$quantita_history[$transactions[$i]->data] = $q;
$i++;
} while ($transactions[$i]->data > $_REQUEST['month-from']);
// print_r($quantita_history);
Db::close_connection($conn);
return $quantita_history;
}
示例4: login
/**
* @fn login
* @short Action method to perform a login.
*/
function login()
{
if ($this->request->is_post()) {
$conn = Db::get_connection();
$user_factory = new User();
$users = $user_factory->find_all(array('where_clause' => "`username` = '{$conn->escape($_POST['username'])}' AND `password` = '" . md5($_POST['password']) . "'", 'limit' => 1));
if (count($users) > 0) {
$user = $users[0];
$expires = $_POST['leave_me_registered'] ? Time::next_year() : Time::tomorrow();
Cookie::set('_u', $user->username, $expires, "/", FALSE);
Cookie::set('_uid', md5(Login::magic_phrase . $user->password), $expires, "/", FALSE);
// Annotates the login in the database
$user_login = new UserLogin();
$user_login->user_id = $user->id;
$user_login->performed_at = date("Y-m-d H:i:s");
$user_login->save();
$this->flash(sprintf(l('Welcome, %s'), $user->first), 'info');
// When login is required to access a particular action, we may store controller & action in a session,
// perform login, then redirect to the action requested in the first place
if (isset($_SESSION['redirect_to'])) {
$this->redirect_to(array('controller' => $_SESSION['redirect_to']['controller'], 'action' => $_SESSION['redirect_to']['action']));
} else {
$this->redirect_to(array('controller' => 'home'));
}
Db::close_connection($conn);
} else {
$this->flash(l('Bad username / password'), 'error');
}
}
$this->redirect_to(array('action' => 'index'));
}
示例5: is_blocked
/**
* @fn is_blocked($ip_addr)
* @short Returns <tt>TRUE</tt> if <tt>ip_addr</tt> is in the blacklist,
* <tt>FALSE</tt> otherwise.
* @param ip_addr The IP address to test.
*/
public static function is_blocked($ip_addr)
{
$conn = Db::get_connection();
$bip_factory = new self();
$ret = $bip_factory->find_all(array('where_clause' => "`ip_addr` = '{$conn->escape($ip_addr)}'"));
Db::close_connection($conn);
return count($ret) > 0;
}
示例6: delete_rows
function delete_rows($table, $primary_key, $keys)
{
$conn = Db::get_connection();
foreach ($keys as $key) {
$conn->prepare("DELETE FROM `{$conn->escape($table)}` WHERE `{$conn->escape($primary_key)}` = '{$conn->escape($key)}' LIMIT 1");
$conn->exec();
}
Db::close_connection($conn);
}
示例7: check_spam_signature
/**
* @fn check_spam_signature
* @short Checks whether the string of text has a recognized spam signature.
* @param $text The text that is used to calculate the spam signature.
*/
public static function check_spam_signature($text)
{
$conn = Db::get_connection();
$signature = self::get_spam_signature($text);
$sig_factory = new SpamSignature();
$matches = $sig_factory->find_all(array('where_clause' => "`signature` = '{$conn->escape($signature)}'"));
Db::close_connection($conn);
return count($matches) > 0;
}
示例8: count_by_ip
/**
* @fn count_by_ip($the_ip)
* @short Returns the count of blocked visits for the desired IP address.
* @the_ip An IP address.
*/
public static function count_by_ip($the_ip)
{
$conn = Db::get_connection();
$conn->prepare("SELECT COUNT(*) FROM `{1}` WHERE `ip_addr` = '{2}'", $this->get_table_name(), $the_ip);
$conn->exec();
$ret = $conn->result(0);
Db::close_connection($conn);
return $ret;
}
示例9: for_range_and_order
public static function for_range_and_order($isin, $date_from, $date_to, $order_by, $sort_dir)
{
$conn = Db::get_connection();
$quote = new Quote();
$quotes = $quote->find_by_query('SELECT `id`, `quotazione` ' . 'FROM `creso_quotazioni` ' . "WHERE `isin` = '{$conn->escape($isin)}' " . "AND `data` > '{$conn->escape($date_from)}' " . "AND `data` < '{$conn->escape($date_to)}' " . "ORDER BY `{$conn->escape($order_by)}` {$conn->escape(strtoupper($sort_dir))} " . 'LIMIT 1');
// print_r($quotes);
Db::close_connection($conn);
return $quotes[0];
}
示例10: software
/**
* @fn software
* @short Action method that generates the feed of software releases.
*/
public function software()
{
$conn = Db::get_connection();
$release_factory = new SoftwareRelease();
if (isset($_GET['id']) && is_numeric($_GET['id'])) {
$this->releases = $release_factory->find_all(array('where_clause' => '`released` = 1 ' . 'AND `software_id` = \'' . $conn->escape($_GET['id']) . '\' ', 'order_by' => '`date` DESC '));
} else {
$this->releases = $release_factory->find_by_query('SELECT MAX(`software_releases`.`id`) AS `id`, `software_releases`.`software_id`, MAX(`software_releases`.`version`) AS `version`, MAX(`software_releases`.`date`) AS `date` ' . 'FROM `softwares` ' . 'LEFT JOIN `software_releases` ON `softwares`.`id` = `software_releases`.`software_id` ' . 'WHERE `software_releases`.`released` = 1 ' . 'GROUP BY `softwares`.`id` ' . 'ORDER BY `date` DESC ');
}
Db::close_connection($conn);
}
示例11: is_logged_in
static function is_logged_in()
{
if (!isset(Login::$logged_in)) {
Login::$logged_in = FALSE;
if (!empty($_COOKIE['username'])) {
$conn = Db::get_connection();
$user_factory = new User();
$users = $user_factory->find_all(array('where_clause' => "`utente` = '{$conn->escape($_COOKIE['username'])}'", 'limit' => 1));
if (count($users) > 0) {
$user = $users[0];
Login::$logged_in = md5($user->utente . self::magic_phrase) == @$_COOKIE['userID'];
}
Db::close_connection($conn);
}
}
return Login::$logged_in;
}
示例12: timeline
public static function timeline($isin, $quantita, $month_from, $month_to)
{
$payments = array();
$conn = Db::get_connection();
$stock = new Stock();
if (!$stock->find_by_id($isin)) {
return;
}
$yields = PaymentsHelper::yields($isin, $month_from, $month_to);
$refunds = PaymentsHelper::refunds($isin, $month_from, $month_to);
$events = array_merge($yields, $refunds);
$payments = array();
foreach ($events as $event) {
if (is_array($quantita)) {
// reset() rewinds array's internal pointer to the first element and returns the value of the first array element, or FALSE if the array is empty.
$q = reset($quantita);
foreach ($quantita as $date => $value) {
if (strtotime($date) < $event->timestamp) {
break;
}
$q = $value;
}
} else {
$q = $quantita;
}
if ($event->tipo == 'rimborso') {
switch ($event->stock->tipo) {
case 'obbligazione':
$event->importo *= $q / 100;
break;
default:
$event->importo *= $q;
}
} else {
$event->importo *= $q;
}
$event->quantita = $q;
$payments[] = $event;
}
// print_r($payments);
Db::close_connection($conn);
return $payments;
}
示例13: lookup_host_and_cache
/**
* @fn lookup_host_and_cache($ip_addr)
* @short Obtains the hostname for the given IP address.
* @param ip_addr The IP address.
*/
private static function lookup_host_and_cache($ip_addr)
{
$conn = Db::get_connection();
$hostname = $ip_addr;
// Attempt to retrieve the hostname from the lookup table...
$conn->prepare("SELECT `hostname` " . "FROM `hosts` " . "WHERE `ip_addr` = '{1}' " . "LIMIT 1", $ip_addr);
$lookup_result = $conn->exec();
if ($conn->num_rows() > 0) {
// Got it
$hostname = $conn->result(0);
} else {
// Resolve the host name with a call to gethostbyaddr
$hostname = gethostbyaddr($ip_addr);
// Store it in the lookup table for later
$conn->prepare("INSERT INTO `hosts` (`ip_addr`,`hostname`,`last_update`) " . "VALUES ('{1}', '{2}', NOW())", $ip_addr, $hostname);
$conn->exec();
}
Db::close_connection($conn);
return $hostname;
}
示例14: chg2eur
static function chg2eur($divisa = 'USD', $date = NULL)
{
if ($date == NULL) {
$date = date('Y-m-d H:i:s');
}
if (!isset(self::$cache[$date])) {
$conn = Db::get_connection();
$change_factory = new self();
$changes = $change_factory->find_all(array('where_clause' => empty($date) ? '1' : "`data` <= '{$conn->escape($date)}'", 'order_by' => '`data` DESC', 'limit' => 1));
$change = $changes[0];
self::$cache[$date] = array('usd2eur' => $change->usd2eur, 'aud2eur' => $change->aud2eur, 'try2eur' => $change->try2eur, 'zar2eur' => $change->zar2eur, 'brl2eur' => $change->brl2eur, 'gbp2eur' => $change->gbp2eur, 'rub2eur' => $change->rub2eur);
Db::close_connection($conn);
}
switch ($divisa) {
case 'USD':
return self::$cache[$date]['usd2eur'];
break;
case 'AUD':
return self::$cache[$date]['aud2eur'];
break;
case 'TRY':
return self::$cache[$date]['try2eur'];
break;
case 'ZAR':
return self::$cache[$date]['zar2eur'];
break;
case 'BRL':
return self::$cache[$date]['brl2eur'];
break;
case 'GBP':
return self::$cache[$date]['gbp2eur'];
case 'RUB':
return self::$cache[$date]['rub2eur'];
}
return 1;
}
示例15: _init_software
/**
* @fn _init_software
* @short Private method that initializes repetitive members of software product page actions.
*/
private function _init_software()
{
$conn = Db::get_connection();
if (isset($_REQUEST['software_name'])) {
$software_factory = new Software();
$softwares = $software_factory->find_all(array('where_clause' => '`name` = \'' . $conn->escape($_REQUEST['software_name']) . '\' AND `type` = \'' . $conn->escape($_REQUEST['software_type']) . '\'', 'limit' => 1));
if (count($softwares) > 0) {
$this->software = $softwares[0];
} else {
$softwares = $software_factory->find_by_query('SELECT `softwares`.`id` ' . 'FROM `softwares` ' . 'LEFT JOIN `software_typos` ON `softwares`.`id` = `software_typos`.`software_id` ' . 'WHERE `software_typos`.`typo` = \'' . $conn->escape($_REQUEST['software_name']) . '\' ' . 'LIMIT 1');
if (count($softwares) > 0) {
$this->software = $softwares[0];
header(sprintf('Location: http://%s%s', $_SERVER['HTTP_HOST'], $this->software->url_to_detail($_REQUEST['subview'])));
exit;
} else {
HTTP::error(404);
}
}
$_REQUEST['id'] = $this->software->id;
} else {
if (isset($_GET['id'])) {
$this->software = new Software();
if ($this->software->find_by_id($_GET['id']) === FALSE) {
$this->flash(l('No such software product!'), 'error');
$this->redirect_to(array('action' => 'index'));
}
} else {
HTTP::error(404);
}
}
$this->software->has_many('software_releases', array('where_clause' => '`released` = \'1\''));
$releases = $this->software->software_releases;
usort($releases, array($releases[0], 'sort_releases'));
$this->release = $releases[0];
$this->software->software_releases = $releases;
Db::close_connection($conn);
}