本文整理汇总了PHP中Db::get_connection方法的典型用法代码示例。如果您正苦于以下问题:PHP Db::get_connection方法的具体用法?PHP Db::get_connection怎么用?PHP Db::get_connection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Db
的用法示例。
在下文中一共展示了Db::get_connection方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: 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'));
}
示例2: roi_with_timeline
public static function roi_with_timeline($isin, $username, $month_from, $month_to)
{
$conn = Db::get_connection();
$stock = new Stock();
if (!$stock->find_by_id($isin)) {
return;
}
$portfolio_stock_factory = new PortfolioStock();
$portfolio_stocks = $portfolio_stock_factory->find_all(array('where_clause' => "`isin` = '{$conn->escape($isin)}' " . "AND `utente` = '{$conn->escape($username)}'"));
if (count($portfolio_stocks) == 0) {
return;
}
$portfolio_stock = $portfolio_stocks[0];
$quantita = self::quantita_history($isin, $username, $month_from);
switch ($stock->tipo) {
case 'obbligazione':
$investito = $portfolio_stock->prezzo * $portfolio_stock->quantita / 100;
break;
default:
$investito = $portfolio_stock->prezzo * $portfolio_stock->quantita;
}
$investito = Change::convert($investito, $stock->divisa);
$roi = PianificatoreHelper::roi_with_timeline($isin, $quantita, $month_from, $month_to, $investito);
foreach ($roi->payments as $payment) {
$payment->portfolio_stock = $portfolio_stock;
}
// print_r($roi);
return $roi;
}
示例3: 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);
}
示例4: get_connection
protected function get_connection()
{
if (!isset($this->conn)) {
$this->conn = Db::get_connection();
}
return $this->conn;
}
示例5: sql_inner
public static function sql_inner($forms)
{
$db = Db::get_connection();
$db->exec('SET CHARACTER SET utf8');
$result = $db->prepare($forms[0]);
$counter = count($forms);
echo $counter;
switch ($counter) {
case 2:
$result->bindParam(':login', $forms['login'], PDO::PARAM_INT);
break;
case 3:
$result->bindParam(':login', $forms['login'], PDO::PARAM_INT);
$result->bindParam(':password', $forms['password'], PDO::PARAM_INT);
break;
case 8:
$result->bindParam(':login', $forms['login'], PDO::PARAM_INT);
$result->bindParam(':password', $forms['password'], PDO::PARAM_INT);
$result->bindParam(':first_name', $forms['first_name'], PDO::PARAM_INT);
$result->bindParam(':last_name', $forms['last_name'], PDO::PARAM_INT);
$result->bindParam(':surname', $forms['surname'], PDO::PARAM_INT);
$result->bindParam(':index', $forms['index'], PDO::PARAM_INT);
$result->bindParam(':address', $forms['address'], PDO::PARAM_INT);
break;
}
$result->execute();
return $result;
}
示例6: refunds
public static function refunds($isin, $month_from, $month_to)
{
$payments = array();
$conn = Db::get_connection();
$stock = new Stock();
if (!$stock->find_by_id($isin)) {
return;
}
switch ($stock->tipo) {
case 'azione':
break;
case 'obbligazione':
$bond_factory = new Bond();
$bonds = $bond_factory->find_all(array('where_clause' => "`isin` = '{$conn->escape($isin)}' " . "AND `scadenza` >= '{$conn->escape($month_from)}' " . "AND `scadenza` <= '{$conn->escape($month_to)}' "));
if (count($bonds) > 0) {
$bond = $bonds[0];
$payment = new Payment();
$payment->stock = $stock;
$payment->bond = $bond;
$payment->timestamp = strtotime($bond->scadenza);
$payment->importo = $payment->bond->prezzo_rimborso;
$payment->tipo = 'rimborso';
$payments[] = $payment;
}
break;
}
return $payments;
}
示例7: 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;
}
示例8: 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);
}
示例9: 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;
}
示例10: 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;
}
示例11: 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];
}
示例12: 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);
}
示例13: action
public static function action()
{
$db = Db::get_connection();
$db_name = $_POST['surname'];
$db_revenue = $_POST['revenue'];
$db_loan = $_POST['loan'];
$db_debt = $_POST['debt'];
$db_founder = $_POST['founder'];
$db_obligation = $_POST['obligation'];
$db_date = $_POST['date'];
$db->query("CREATE TABLE IF NOT EXISTS {$db_name} LIKE main");
$db->query("INSERT INTO {$db_name} (surname, revenue, loan, debt, \n\t\t\tfounder, obligation, date)\n\t\t\tVALUES ('{$db_name}', '{$db_revenue}', '{$db_loan}', '{$db_debt}', '{$db_founder}', \n\t\t\t'{$db_obligation}', '{$db_date}')");
}
示例14: 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;
}
示例15: update_versiontracker_ratings
/**
* @fn update_versiontracker_ratings
* @short Action method that updates the VersionTracker ratings for software products.
*/
public function update_versiontracker_ratings()
{
$conn = Db::get_connection();
error_reporting(E_ALL | E_STRICT);
$sw = new Software();
$softwares = $sw->find_all();
foreach ($softwares as $software) {
$software->has_one('version_tracker_entries');
if ($software->version_tracker_entry && $software->version_tracker_entry->vt_id != 0) {
$vt = new VTRatingsParser($software->version_tracker_entry->vt_id);
$vt->parse();
$software->version_tracker_entry->rating = $vt->rating;
$software->version_tracker_entry->save();
}
}
$this->render(NULL);
Db::close_connection($conn);
}