public static function getConn() { if (!isset(self::$conn)) { self::$conn = new PDO('mysql:host=localhost;dbname=history_app;charset=utf8', 'root', '', array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8", PDO::MYSQL_ATTR_INIT_COMMAND => "SET SQL_MODE=ANSI_QUOTES")); } return self::$conn; }
private static function connect() { self::$conn = new mysqli('localhost', 'root', 'root', 'arbetsprov'); if (self::$conn->connect_error) { error_log('Connection to database failed!'); } }
public function __construct($user, $id = -1) { DB::conn(); $this->exercises = array(); $this->user = $user; $this->id = $id; }
function connect() { switch (DBTYPE) { case 'mysql': if (self::$conn = mysql_connect(DBSERVER . ':' . DBSERVER_PORT, DBUSER, DBPASSWD)) { if (mysql_select_db(DBNAME, self::$conn)) { mysql_query("SET character_set_connection=" . DBCHARSET . ", character_set_results=" . DBCHARSET . ", character_set_client=binary", self::$conn); } else { echo 'can not select db'; exit; } } else { echo 'can not connect db'; exit; } break; case 'mysqli': if (self::$conn = new mysqli(DBSERVER, DBUSER, DBPASSWD, DBNAME, DBSERVER_PORT)) { self::$conn->query("SET character_set_connection=" . DBCHARSET . ", character_set_results=" . DBCHARSET . ", character_set_client=binary"); } else { echo 'can not connect db'; exit; } break; } }
/** * simpleReserve * * @TODO 同時間帯に別のチャンネルを予約している場合に警告 * 同一番組をすでに予約している場合は上書きする */ public static function simpleReserve($program_disc) { $db = DB::conn(); $program = Program::get($program_disc); $row = array('program_disc' => $program->program_disc, 'autorec' => 0, 'mode' => 0, 'job' => 0); return $db->replace(self::TABLE, $row); }
public function updateValue($old, $new) { $query = DB::conn()->prepare('UPDATE `examples` SET `value` = :new WHERE `value` = :old'); $query->bindValue(':new', $new, PDO::PARAM_INT); $query->bindValue(':old', $old, PDO::PARAM_INT); $query->execute(); return $query->rowCount(); }
function __construct() { self::$conn = mysql_connect('localhost', 'YOUR_USERNAME_HERE', 'YOUR_PW_HERE'); if (!self::$conn) { die('Could not connect: ' . mysql_error()); } mysql_select_db("YOUR_DB_NAME_HERE", self::$conn); }
public function getNotifications($id_user) { $query = DB::conn()->prepare('SELECT * FROM `notifications` WHERE `id_user` = :id_user'); $query->bindValue(':id_user', $id_user, PDO::PARAM_INT); $query->execute(); return $query->fetchAll(PDO::FETCH_OBJ); }
/** Create the private instance */ private function __construct($host, $username, $password, $database) { try { self::$conn = new PDO("mysql:host=" . $host . ";dbname=" . $database, $username, $password); return self::$conn; } catch (PDOException $e) { print "Error connection to database: " . $e->getMessage(); } }
public function connect() { if (!self::$conn) { self::$conn = @mysql_connect($this->host, $this->username, $this->password) or die(mysql_error()); } mysql_select_db($this->database, self::$conn); mysql_query("set names 'utf8'", self::$conn); return self::$conn; }
public function __construct($acudiente) { $this->conn = DB::conn(); if ($acudiente === null) { $this->sel_programa(); } else { $this->sel_programa_ninos(); } }
static function getConn() { if (is_null(self::$conn)) { //self::$conn = new PDO('mysql:host=dbmy0011.whservidor.com;dbname=renascerpe_1','renascerpe_1','d0m1r2c2'); self::$conn = new PDO('mysql:host=localhost;dbname=sersocial', 'root', 'user00'); self::$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); } return self::$conn; }
/** * コンストラクタ * @param string [$uri=null] DB接続URI情報 */ public function __construct($uri = null) { // DB接続 if (empty($uri)) { $this->conn = DB::connMaster(); } else { $this->conn = DB::conn($uri); } }
/** * Creates the connection */ static function init() { global $databaseConfig; if (!isset($databaseConfig)) { $databaseConfig = array('server' => SS_DATABASE_SERVER, 'username' => SS_DATABASE_USERNAME, 'password' => SS_DATABASE_PASSWORD, 'database' => SS_DATABASE_NAME); } self::$conn = new mysqli($databaseConfig['server'], $databaseConfig['username'], $databaseConfig['password'], $databaseConfig['database']); self::$conn->query("set sql_mode='ansi'"); }
public static function getInstance() { try { self::$conn = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME, "3306"); self::$conn->set_charset("utf8"); } catch (Exception $e) { echo "Error 101. Falló la conexión con MySQL: (" . $mysqli->connect_errno . ") " . $mysqli->connect_error; } return self::$conn; }
public static function getAll() { $items = array(); $db = DB::conn(); $rows = $db->rows('SELECT * FROM ' . self::TABLE . ' ORDER BY name_jp'); foreach ($rows as $row) { $items[] = new self($row); } return $items; }
public static function getDB() { if (self::$conn instanceof PDO) { return self::$conn; } $host = $GLOBALS['set_host']; $db = $GLOBALS['set_db']; $user = $GLOBALS['set_user']; $pass = $GLOBALS['set_pass']; return self::$conn = new PDO("mysql:host={$host};dbname={$db}", "{$user}", "{$pass}"); }
public static function getInstance() { try { self::$conn = new PDO("mysql:host=" . HOST . ";dbname=" . DBNAME, USER, PASS); self::$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); self::$conn->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_OBJ); } catch (PDOException $e) { echo "Connection failed: " . $e->getMessage(); } return self::$conn; }
public static function init() { $host = ConfigManifest::get_config('Database.host'); $user = ConfigManifest::get_config('Database.user'); $pass = ConfigManifest::get_config('Database.password'); $database = ConfigManifest::get_config('Database.db'); if ($host && $user && $pass && $database) { self::$conn = new mysqli($host, $user, $pass, $database); } else { user_error('I can\'t find any database records', E_USER_WARNING); } }
public function conn() { if (DB::$conn == null) { try { DB::$conn = new PDO('mysql:host=' . DB::$host . ';dbname=' . DB::$dbname . ';charset=UTF8', DB::$login, DB::$pass, array(PDO::ATTR_PERSISTENT => true)); } catch (PDOException $error) { echo $error->getMessage(); exit; } } return DB::$conn; }
public function addItemsFromSQL($sql, $fieldValue = "id", $fieldLabel = "name", $connName = null, $now = false) { if (!$this->initialized && !$now) { $this->toAdd[] = "fromSQL#####" . $sql . "#####" . $fieldValue . "#####" . $fieldLabel . "#####" . $connName; return; } $rs = DB::conn($connName)->query($sql); while (!$rs->EOF) { $this->items[$rs->fields[$fieldValue]] = $rs->fields[$fieldLabel]; $rs->moveNext(); } $rs->close(); }
/** * @return PDO */ public static function conn() { if (self::$conn === null) { try { self::$conn = new PDO('mysql:host=' . DB_HOST . ';dbname=' . DB_NAME, DB_USER, DB_PASS); self::$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); self::$conn->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC); } catch (PDOException $e) { die('Database connection could not be established.'); } } return self::$conn; }
/** * validation for username and password * @throws RecordnotFoundException * @param $username * @param $password **/ public function authenticate($username, $password) { $this->username = $username; $this->password = $password; if (!$this->validate()) { throw new ValidationException("Invalid Username/Password"); } $db = DB::conn(); $row = $db->row("SELECT * FROM user_info \n WHERE username = ? AND user_password = ?", array($username, $password)); if (!$row) { throw new RecordNotFoundException("Record not found"); } return new self($row); }
/** * create new thread * @param Comment $comment * @throws ValidationException */ public function create(Comment $comment) { $this->validate(); $comment->validate(); if ($this->hasError() || $comment->hasError()) { throw new ValidationException('invalid thread or comment'); } $db = DB::conn(); $db->begin(); $db->query('INSERT INTO thread SET title = ?, created = NOW()', array($this->title)); $this->id = $db->lastInsertId(); // write first comment at the same time $this->write($comment); $db->commit(); }
public static function Connect($host, $user, $pass, $db) { self::$host = $host; self::$pass = $pass; self::$user = $user; self::$db = $db; self::$conn = @mysql_connect($host, $user, $pass) or self::msg('连接数据库失败!可能是mysql数据库用户名或密码不正确!'); self::selectdb(self::$db); if (self::version() > '4.1') { mysql_query("SET NAMES 'GBK'"); } if (self::version() > '5.0.1') { mysql_query("SET sql_mode=''"); } }
public function create() { redirect_guest_user(LOGIN_URL); $thread = new Thread(); $comment = new Comment(); $page = Param::get('page_next', 'create'); $auth_user = User::getAuthenticated(); $categories = Category::getAll(); switch ($page) { case 'create': break; case 'create_end': $thread->title = trim_collapse(Param::get('title')); $thread->category_id = Param::get('category'); $thread->user_id = $auth_user->id; $comment->user_id = $auth_user->id; $comment->body = trim(Param::get('body')); $db = DB::conn(); try { $db->begin(); $thread->create($comment); $follow = new Follow(); $follow->thread_id = $thread->id; $follow->user_id = $auth_user->id; $follow->last_comment = Comment::getFirstInThread($thread)->id; $follow->create(); $db->commit(); redirect(VIEW_THREAD_URL, array('id' => $thread->id)); } catch (ValidationException $e) { $page = 'create'; $db->rollback(); } catch (CategoryException $e) { $thread->validation_errors['category']['exists'] = true; $page = 'create'; $db->rollback(); } break; default: throw new PageNotFoundException("{$page} is not found"); break; } $title = 'Create Thread'; $this->set(get_defined_vars()); $this->render($page); }
/** * Starts the DB connection * Private method to call from other static methods of the class */ private static function _init() { if (self::$connected) { return; } try { $conn = new PDO(self::$driver . ':' . self::$dsn, isset(self::$username) ? self::$username : null, isset(self::$password) ? self::$password : null); self::$connected = true; } catch (Exception $e) { self::_logError($e); throw $e; } // Si on utilise Mysql, on passe en UTF-8 if (self::$driver == 'mysql') { $conn->query('SET NAMES utf8'); } self::$conn = $conn; }
/** * To validate user registration * @throws IncompleteFieldsException, ValidationException, ExistingUserException * @param $infos(array) */ public function userRegistration(array $user_info) { extract($user_info); $defaults = array('username' => $username, 'user_password' => $user_password, 'fname' => $fname, 'lname' => $lname, 'email' => $email, 'created' => date('Y-m-d H:i:s')); $this->username = $username; $this->password = $user_password; $this->email = $email; if (!$this->validate()) { throw new ValidationException("Invalid Username/Password"); } $db = DB::conn(); $query = "SELECT username, email FROM user_info\n WHERE username = ? OR email = ?"; $params = array($username, $email); $search = $db->row($query, $params); if ($search) { throw new ExistingUserException(notice("Username/Email already used", "error")); } $row = $db->insert('user_info', $defaults); }
public static function getConnection($type) { /***************** Configuração no servidor web ************/ // static $username = '******'; // static $password = '******'; // static $dbname = 'u802748204_dog'; // static $IPHost = 'mysql.hostinger.com.br'; /***************** Configuração na sua máquina ************/ static $username = '******'; static $password = '******'; static $dbname = 'petse150_petservico'; static $IPHost = 'localhost'; if (!isset(self::$conn)) { if ($type == 'medoo') { self::$conn = new medoo(['database_type' => 'mysql', 'database_name' => $dbname, 'server' => $IPHost, 'username' => $username, 'password' => $password, 'charset' => 'utf8']); } else { self::$conn = new PDO('mysql:host=' . $IPHost . ';dbname=' . $dbname, $username, $password, array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8")); } } return self::$conn; }
public function __construct() { $this->conn = DB::conn(); }