本文整理汇总了PHP中Database::get_instance方法的典型用法代码示例。如果您正苦于以下问题:PHP Database::get_instance方法的具体用法?PHP Database::get_instance怎么用?PHP Database::get_instance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Database
的用法示例。
在下文中一共展示了Database::get_instance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: dbconnect
private static function dbconnect()
{
if (!self::$db) {
self::$db = Database::get_instance();
}
return self::$db;
}
示例2: create_user
public function create_user()
{
// If there are no users then let's create one.
$db = Database::get_instance();
$db->query('SELECT * FROM `users` LIMIT 1');
if ($db->has_rows() && !Auth::get_instance()->logged_in()) {
Flash::set('<p class="flash validation">Sorry but to create new users, you must be logged in.</p>');
Core_Helpers::redirect(WEB_ROOT . 'login/');
}
$validator = Error::instance();
if (isset($_POST['email'])) {
$validator->email($_POST['email'], 'email');
$validator->blank($_POST['username'], 'username');
$validator->blank($_POST['password'], 'password');
$validator->passwords($_POST['password'], $_POST['confirm_password'], 'confirm_password');
$user = new Users();
if ($user->select(array('username' => $_POST['username']))) {
$validator->add('username', 'The username <strong>' . htmlspecialchars($_POST['username']) . '</strong> is already taken.');
}
if ($validator->ok()) {
$user = new Users();
$user->load($_POST);
$user->level = 'admin';
$user->insert();
Flash::set('<p class="flash success">User created successfully.</p>');
Core_Helpers::redirect(WEB_ROOT . 'login/');
}
}
$this->data['error'] = $validator;
$this->load_template('create_user');
}
示例3: get_active
/**
* Obtenemos una noticia a mostrar.
*/
public static function get_active()
{
$id = Database::get_instance()->query('SELECT id FROM noticia WHERE estado = ? LIMIT 1', self::ESTADO_VISIBLE)->get_var(Database_Query::FIELD_INT);
if ($id !== NULL) {
return new Model_Noticia($id);
} else {
return NULL;
}
}
示例4: __construct
public function __construct()
{
foreach (Database::get_instance()->query("select * from server order by name asc")->fetchAll() as $row) {
self::$servers[$row->id] = $row->name;
}
$this->navi = new Template('navigation');
$this->navi->load_data('servers', self::$servers);
$this->navi->load_data('extended', array());
}
示例5: cantidad
/**
* Cantidad de comentarios en post y fotos.
* @param int $estado
* @return int
*/
public static function cantidad($estado = NULL)
{
if ($estado === NULL) {
$c = Database::get_instance()->query('SELECT COUNT(*) FROM post_comentario')->get_var(Database_Query::FIELD_INT);
$c += Database::get_instance()->query('SELECT COUNT(*) FROM foto_comentario')->get_var(Database_Query::FIELD_INT);
} else {
$c = Database::get_instance()->query('SELECT COUNT(*) FROM post_comentario WHERE estado = ?', $estado)->get_var(Database_Query::FIELD_INT);
$c += Database::get_instance()->query('SELECT COUNT(*) FROM foto_comentario WHERE estado = ?', $estado)->get_var(Database_Query::FIELD_INT);
}
return $c;
}
示例6: find_this_query
public static function find_this_query($sql, $params = array())
{
$database = Database::get_instance();
$dbh = $database->get_connection();
$results_array = array();
$result = $database->query($sql, $params);
for ($i = 0, $length = count($result); $i < $length; $i++) {
$results_array[] = self::instantiation($result[$i]);
}
return $results_array;
}
示例7: create
public static function create($aspect_type = '', $aspect_data = '')
{
$output_object = null;
if (is_numeric($aspect_type)) {
// a number got passed in, so we'll try to go from aspect_type_id
// aha, it looks like we'll need to look up what the name should be
// if we get passed an ID only.
$db = Database::get_instance();
$sql = "SELECT id, aspect_name FROM aspect_types WHERE id = :id";
$stmt = $db->prepare($sql);
$stmt->bindParam(':id', $aspect_type, PDO::PARAM_STR);
if ($stmt->execute()) {
$row = $stmt->fetchObject();
$cleaned_class_name = code_safe_name($row->aspect_name);
$class_name = $cleaned_class_name . 'Aspect';
if (class_exists($class_name)) {
// a custom class DOES exist, so create one.
$new_aspect = new $class_name();
$new_aspect->aspect_type = $aspect_type;
} else {
$new_aspect = new Aspect();
$new_aspect->aspect_type = $aspect_type;
}
} else {
return false;
}
} else {
// we got a string, so we'll try to create a custom aspect of that type,
// if such a class is defined.
$db = Database::get_instance();
$sql = "SELECT id, aspect_name FROM aspect_types WHERE aspect_name = :name";
$stmt = $db->prepare($sql);
$stmt->bindParam(':name', $aspect_type, PDO::PARAM_STR);
if ($stmt->execute()) {
$row = $stmt->fetchObject();
$cleaned_class_name = code_safe_name($row->aspect_name);
$class_name = $cleaned_class_name . 'Aspect';
if (class_exists($class_name)) {
// a custom class DOES exist, so create one.
$new_aspect = new $class_name();
$new_aspect->aspect_type = $row->id;
} else {
$new_aspect = new Aspect();
$new_aspect->aspect_type = $row->id;
}
} else {
return false;
}
}
if ($aspect_data != '') {
$new_aspect->aspect_data = $aspect_data;
}
return $new_aspect;
}
示例8: load_full_subjects_array
public function load_full_subjects_array()
{
$db = Database::get_instance();
$query = $db->prepare("SELECT id FROM subject_types");
if ($query->execute()) {
while ($row = $query->fetch()) {
$new_subject = new SubjectType();
$new_subject->load($row['id']);
$this->full_subjects_array[$new_subject->id] = $new_subject->parent_id;
}
}
}
示例9: __construct
private function __construct()
{
session_set_cookie_params(7200, "/");
// 2 hours session time
session_start();
if (!empty($_SESSION['username'])) {
self::$is_logged_in = true;
self::$logged_user = array('id' => $_SESSION['user_id'], 'username' => $_SESSION['username']);
}
$this->table = 'users';
$db_object = Database::get_instance();
$this->dbConn = $db_object::get_db();
}
示例10: results
/**
* This implementation does not handle AND connectives between players.
* TODO: rewrite the whole crap
*/
public function results($uniqid = false, $page = 1)
{
session_start();
if (empty($_POST)) {
if (isset($_SESSION['post'][$uniqid])) {
$_POST = $_SESSION['post'][$uniqid];
}
} else {
$uniqid = uniqid();
$_SESSION['post'][$uniqid] = $_POST;
}
if (!empty(array_filter($_POST['player']))) {
$params = array();
$server_join = "";
if (isset($_POST['server']) && $_POST['server']) {
$params[":srv"] = $_POST['server'];
$server_join .= "RIGHT OUTER JOIN server AS s " . "ON s.id = g.server AND s.id = :srv ";
}
$where = array();
foreach ($_POST['player'] as $idx => $kw) {
$idx = (int) $idx;
// injection attempts shall only fuck up the results
if ($kw[0] === '"' && $kw[strlen($kw) - 1] === '"') {
$kw = substr($kw, 1, -1);
$kw = str_replace("%", "\\%", $kw);
}
$param = ":like" . $idx;
$where[] = " p.name LIKE " . $param;
$params[$param] = $kw;
}
$sql = "SELECT SQL_CALC_FOUND_ROWS DISTINCT g.* " . "FROM player AS p INNER JOIN game AS g ON g.id = p.game " . $server_join . "WHERE " . implode(" OR ", $where) . " ORDER BY g.starttime DESC LIMIT :offset, :max";
$db = Database::get_instance();
$sth = $db->prepare($sql);
// $params[':offset'] = ($page - 1) * Game::$limit;
// $params[':max'] = Game::$limit;
// $sth->execute($params); // LIMIT params need type info :/
$sth->bindParam(':max', Game::$limit, PDO::PARAM_INT);
$sth->bindValue(':offset', ($page - 1) * Game::$limit, PDO::PARAM_INT);
foreach ($params as $key => $value) {
$sth->bindValue($key, $value);
}
$sth->execute();
$total = (int) $db->query("SELECT FOUND_ROWS() AS t")->fetch()->t;
$resultview = new Template('gamelist', array('list' => $sth->fetchAll(PDO::FETCH_CLASS, "Game"), 'pagination' => gamelist::pagination($page, $total, App()->site_url("search/results/{$uniqid}"))));
$this->form($_POST);
$resultview->render();
} else {
App()->redirect("search");
}
}
示例11: authenticate
public function authenticate()
{
$db = Database::get_instance();
$pwdField = static::$passwordField;
$usernameField = static::$usernameField;
$pass = $db->fetch_array($db->query("SELECT " . static::$passwordField . " FROM " . static::$tableName . " WHERE " . static::$usernameField . "='" . $this->{$usernameField} . "' LIMIT 1"));
if ($this->{$pwdField} == $pass[0][0]) {
$result_id = $db->fetch_array($db->query("SELECT ID FROM " . static::$tableName . " WHERE " . static::$usernameField . "='" . $this->user . "' LIMIT 1"));
$this->id = $result_id[0][0];
return true;
} else {
return false;
}
}
示例12: aspect_flavors
public function aspect_flavors()
{
$output = '';
$db = Database::get_instance();
$query = $db->prepare("SELECT DISTINCT flavor from aspect_types ORDER BY flavor ASC");
if ($query->execute()) {
foreach ($query->fetchAll() as $row) {
$output .= '<option value="' . $row['flavor'] . '">' . $row['flavor'] . '</option>';
}
return $output;
} else {
return false;
}
}
示例13: print_last_logs
public function print_last_logs($number = '5')
{
$output = '<ul>';
$db = Database::get_instance();
$query = $db->prepare("SELECT * FROM log ORDER BY id DESC LIMIT 10");
$data = array($number);
if ($query->execute($data)) {
while ($row = $query->fetch()) {
$output .= '<li>' . $row['message'] . ' - logged at ' . $row['time'] . '</li>';
}
}
$output .= '</ul>';
return $output;
}
示例14: install
public static function install($app)
{
if (file_exists(DOC_ROOT . 'apps/' . $app . '/tables.sql')) {
if (is_writable(DOC_ROOT . 'apps/' . $app . '/tables.sql')) {
// Create tables
$sql = file_get_contents(DOC_ROOT . 'apps/' . $app . '/tables.sql');
// Do this to split up creations to one per query.
$queries = explode('#', $sql);
$db = Database::get_instance();
foreach ($queries as $query) {
$db->query($query);
}
rename(DOC_ROOT . 'apps/' . $app . '/tables.sql', DOC_ROOT . 'apps/' . $app . '/tables.sql.bak');
} else {
die('<h1>You have not installed this app, either run <strong>' . DOC_ROOT . 'apps/' . $app . '/tables.sql' . '</strong> manually and delete the file or change chmod this file so that it is writable by PHP.</h1>');
}
}
}
示例15: build
public function build()
{
$db = Database::get_instance();
$values = $this->current_object->get_fields();
$options = array();
foreach ($values as $value) {
$res = $db->query('SELECT `' . $value . '` FROM ' . $this->table)->result;
$type = mysql_field_type($res, 0);
$extra = mysql_field_flags($res, 0);
$notnullsearch = strpos($extra, 'not_null');
// If value can not be NULL lets add blank as a error check
if ($notnullsearch === false) {
$options['validation'] = '';
} else {
$options['validation'] = 'blank';
}
$options['type'] = $type === 'blob' ? 'htmleditor' : 'text';
$options['type'] = $type === 'timestamp' ? 'timestamp' : $options['type'];
$options['type'] = $value === 'password' ? 'password' : $options['type'];
// Grab rows where field name matches
$value_info = new Field_Information(array('table' => $this->table, 'name' => $value));
if ($value_info->type !== NULL) {
$options['type'] = $value_info->type;
if ($options['type'] === 'file') {
// shouldn't validate for blank if it's a file.... TODO: Come up with a way to validate files
$options['validation'] = '';
}
}
if ($value_info->options !== NULL) {
$exploded_options = explode("\n", $value_info->options);
foreach ($exploded_options as $option) {
if (!empty($option)) {
$option_temp = explode(',', $option);
$options['options'][$option_temp[0]] = $option_temp[1];
}
}
}
$options['value'] = $this->current_object->{$value};
$this->add_field($value, $options);
}
}