本文整理汇总了PHP中DBConnection::connect方法的典型用法代码示例。如果您正苦于以下问题:PHP DBConnection::connect方法的具体用法?PHP DBConnection::connect怎么用?PHP DBConnection::connect使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBConnection
的用法示例。
在下文中一共展示了DBConnection::connect方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: get_db_connection
/**
* @desc returns the currently opened <code>DBConnection</code> instance or if none,
* creates a new one
* @return DBConnection the currently opened <code>DBConnection</code> instance
*/
public static function get_db_connection()
{
if (self::$db_connection === null) {
$data = self::load_config();
self::init_factory($data['dbms']);
self::$db_connection = self::new_db_connection();
self::$db_connection->connect($data);
}
return self::$db_connection;
}
示例2: connect
/**
* Connect
*
* @param bool reconnect default FALSE
* @return bool success
* @throws rdbms.SQLConnectException
*/
public function connect($reconnect = FALSE)
{
if (is_resource($this->handle)) {
return TRUE;
}
// Already connected
if (!$reconnect && FALSE === $this->handle) {
return FALSE;
}
// Previously failed connecting
$this->_obs && $this->notifyObservers(new DBEvent(DBEvent::CONNECT, $reconnect));
if ($this->flags & DB_PERSISTENT) {
$this->handle = mssql_pconnect($this->dsn->getHost(), $this->dsn->getUser(), $this->dsn->getPassword());
} else {
$this->handle = mssql_connect($this->dsn->getHost(), $this->dsn->getUser(), $this->dsn->getPassword());
}
if (!is_resource($this->handle)) {
$e = new SQLConnectException(trim(mssql_get_last_message()), $this->dsn);
xp::gc(__FILE__);
throw $e;
}
xp::gc(__FILE__);
$this->_obs && $this->notifyObservers(new DBEvent(DBEvent::CONNECTED, $reconnect));
return parent::connect();
}
示例3: fetchAll
static function fetchAll()
{
DBConnection::connect();
$result = DBConnection::select('SELECT * FROM post');
$posts = [];
if ($result) {
foreach ($result as $post) {
array_push($posts, new Post($post->id, $post->title, false));
}
}
return $posts;
}
示例4: fetchAll
static function fetchAll()
{
DBConnection::connect();
$result = DBConnection::select('SELECT * FROM user');
$users = [];
if ($result) {
foreach ($result as $user) {
array_push($users, new User($user->id, $user->pseudo, false));
}
}
return $users;
}
示例5: getEvents
public static function getEvents()
{
$db = new DBConnection();
$link = $db->connect();
if ($link != null) {
$query = "SELECT event_name,start_date,end_date,start_time FROM event";
$result = $link->query($query);
$result_array = array();
$index = 0;
while ($row = mysqli_fetch_assoc($result)) {
$result_array[$index] = $row;
$index = $index + 1;
}
$db->closeConnection();
return $result_array;
}
$db->closeConnection();
return null;
}
示例6: connect
/**
* Connect
*
* @param bool reconnect default FALSE
* @return bool success
* @throws rdbms.SQLConnectException
*/
public function connect($reconnect = FALSE)
{
if ($this->handle->connected) {
return TRUE;
}
// Already connected
if (!$reconnect && NULL === $this->handle->connected) {
return FALSE;
}
// Previously failed connecting
try {
$this->handle->connect($this->dsn->getUser(), $this->dsn->getPassword());
$this->_obs && $this->notifyObservers(new DBEvent(__FUNCTION__, $reconnect));
} catch (IOException $e) {
$this->handle->connected = NULL;
$this->_obs && $this->notifyObservers(new DBEvent(__FUNCTION__, $reconnect));
throw new SQLConnectException($e->getMessage(), $this->dsn);
}
return parent::connect();
}
示例7: InitPage
function InitPage($login)
{
$page = $login;
$lastPage = GetSessionVar('s_pageName');
$User = GetSessionVar('User');
if (empty($GLOBALS['page'])) {
$GLOBALS['page'] = '';
}
if (isset($_SERVER['REQUEST_URI']) && strpos($_SERVER['REQUEST_URI'], "login.php") == FALSE && strpos($_SERVER['REQUEST_URI'], "callback") == FALSE) {
SetSessionVar('s_pageLast', $_SERVER['REQUEST_URI']);
}
$dbc = new DBConnection();
global $dbh;
$dbh = $dbc->connect();
if ($login == "login" && !$User) {
# Login required, but the User object isn't there.
if (isset($_COOKIE[COOKIE_REMEMBER])) {
# Try to fetch username from session
require_once dirname(__FILE__) . "/../classes/system/session.class.php";
$Session = new Session();
if (!$Session->validate()) {
exitTo("login.php");
} else {
$User = new User();
$User->loadFromID($Session->_userid);
SetSessionVar("User", $User);
}
} else {
exitTo("login.php");
}
}
$GLOBALS['g_PHPSELF'] = $GLOBALS['page'];
$GLOBALS['g_PAGE'] = $page;
if (isset($_SERVER['HTTP_HOST'])) {
$GLOBALS['g_SITEURL'] = $_SERVER['HTTP_HOST'];
$GLOBALS['g_SITENAME'] = substr($GLOBALS['g_SITEURL'], 0, strlen($GLOBALS['g_SITEURL']) - 4);
$GLOBALS['g_TITLE'] = $GLOBALS['g_SITENAME'];
}
$GLOBALS['g_ERRSTRS'] = array("", "", "", "", "", "", "", "", "", "", "");
$GLOBALS['DEBUG'] = "";
}
示例8: json_encode
<?php
require_once "config/DBConnection.php";
$db = new DBConnection();
$conn = $db->connect();
$userId = $_GET['user_id'];
$pass = $_GET['password'];
//check connection first before doing query
$sql = "SELECT * FROM users WHERE user_id = '{$userId}' AND password = '{$pass}'";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
$user = $result->fetch_object();
$response = array('status' => 'ok', 'message' => 'Successfully Login!', 'user' => $user);
echo json_encode($response);
die;
}
echo json_encode(array('status' => 'error', 'message' => 'Login Failed!'));
$conn->close();
示例9: error_reporting
<?php
/*******************************************************************************
* Copyright (c) 2007-2009 Intalio, Inc.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Antoine Toulme, Intalio Inc.
*******************************************************************************/
// this file should be included in the spec files.
// it will open a connection to a test database.
error_reporting(E_ALL);
ini_set('display_errors', '1');
require_once dirname(__FILE__) . "/../classes/system/dbconnection.class.php";
DBConnection::connect(dirname(__FILE__) . '/test.ini');
示例10: Login
<?php
include 'src/DBConnection.php';
include 'src/Login.php';
$login = new Login();
if ($login->is_session()) {
$login->redirect();
}
if (isset($_POST['submit'])) {
if (!empty($_POST['username']) && !empty($_POST['password'])) {
$dbObj = new DBConnection();
$db = $dbObj->connect();
$username = $_POST['username'];
$password = $_POST['password'];
$login->setDB($db);
$login->setUsername($username);
$login->setPassword($password);
if ($login->verification()) {
if ($login->createSession()) {
$login->redirect();
}
} else {
echo 'username / password is incorrect';
}
}
}
示例11: sizeof
$N = $sent[0];
$K = $sent[1];
$command = '/usr/bin/python /var/www/html/toyapp/toyapp-python/toyapp.py encrypt ' . $file_name . ' ' . $N . ' ' . $K;
echo $command;
//echo '<br />'.$command;
//echo '<br />';
#$result = #exec($command);#
$result = json_decode(exec($command, $status), true);
$size = sizeof($result);
//print_r($result);
$i = 0;
require_once '../includes/shareholdersapi.inc';
$shareholders = get_shareholders($sent[2]);
//print_r($shareholders);
require_once '../includes/DB_Abstraction.inc';
$db_con = new DBConnection();
$db_con->connect();
foreach ($result as $pair) {
$uid = $shareholders[$i]['uid'];
$db_con->insert('secrets', 'fid,uid,secret', "{$sent['2']},'{$uid}','[{$pair['0']},{$pair['1']}]'");
$i++;
echo "<br />Secret {$i}: <input type='text' readonly='readonly' value='[{$pair['0']},{$pair['1']}]'/>";
}
//print_r($result);//. ' <br />';
$db_con->update('file', "url='\\/toyapp\\/repo\\/{$fn}.enc',status=2", "fid={$sent['2']}");
$db_con->disconnect();
//unlink($file_name);
}
?>
</body>
</html>
示例12: array
include 'MembersCtrl.php';
include 'src/Appointment.php';
if (isset($_POST['submit'])) {
$data = array('name' => $_POST['name'], 'address' => $_POST['address'], 'age' => $_POST['age'], 'gender' => $_POST['gender'], 'hospital' => $_POST['hospital'], 'speciality' => $_POST['speciality'], 'appointment' => $_POST['appointment'], 'date' => $_POST['date'], 'time' => $_POST['time'], 'phone' => $_POST['phone'], 'doctor' => $_POST['doctor'], 'age' => $_POST['age'], 'gender' => $_POST['gender'], 'address' => $_POST['address']);
$pass = true;
foreach ($data as $var => $value) {
if (empty($value)) {
echo $var . " is empty!";
$pass = false;
break;
}
}
if ($pass) {
$dbo = new DBConnection();
$db = $dbo->connect();
$appointment = new Appointment();
$appointment->setDB($db);
$appointment->setPatientUser($data['name']);
$appointment->setDoctor($data['doctor']);
$appointment->setDate($data['date']);
$appointment->setTime($data['time']);
$appointment->setSpeciality($data['speciality']);
$appointment->setAppointmentType($data['appointment']);
$appointment->setHospital($data['hospital']);
$appointment->setMobile($data['phone']);
$appointment->setAge($data['age']);
$appointment->setGender($data['gender']);
$appointment->setCurrentUser($members->getSessionUser());
$appointment->setCurrentAddress($data['address']);
if ($appointment->verification()) {
示例13: connect
/**
* Connect
*
* @param bool reconnect default FALSE
* @return bool success
* @throws rdbms.SQLConnectException
*/
public function connect($reconnect = FALSE)
{
if ($this->handle->connected) {
return TRUE;
}
// Already connected
if (!$reconnect && NULL === $this->handle->connected) {
return FALSE;
}
// Previously failed connecting
$this->_obs && $this->notifyObservers(new DBEvent(DBEvent::CONNECT, $reconnect));
try {
$this->handle->connect($this->dsn->getUser(), $this->dsn->getPassword());
$this->_obs && $this->notifyObservers(new DBEvent(DBEvent::CONNECTED, $reconnect));
} catch (IOException $e) {
$this->handle->connected = NULL;
$this->_obs && $this->notifyObservers(new DBEvent(DBEvent::CONNECTED, $reconnect));
throw new SQLConnectException($e->getMessage(), $this->dsn);
}
try {
$this->handle->exec('set names LATIN1');
// Figure out sql_mode and update formatter's escaperules accordingly
// - See: http://bugs.mysql.com/bug.php?id=10214
// - Possible values: http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html
// "modes is a list of different modes separated by comma (,) characters."
$modes = array_flip(explode(',', this(this($this->handle->consume($this->handle->query("show variables like 'sql_mode'")), 0), 1)));
} catch (IOException $e) {
// Ignore
}
// NO_BACKSLASH_ESCAPES: Disable the use of the backslash character
// (\) as an escape character within strings. With this mode enabled,
// backslash becomes any ordinary character like any other.
// (Implemented in MySQL 5.0.1)
isset($modes['NO_BACKSLASH_ESCAPES']) && $this->formatter->dialect->setEscapeRules(array('"' => '""'));
return parent::connect();
}
示例14: connect
/**
* Connect
*
* @param bool reconnect default FALSE
* @return bool success
* @throws rdbms.SQLConnectException
*/
public function connect($reconnect = FALSE)
{
if (is_resource($this->handle)) {
return TRUE;
}
// Already connected
if (!$reconnect && FALSE === $this->handle) {
return FALSE;
}
// Previously failed connecting
// Connect via local sockets if "." is passed. This will not work on
// Windows with the mysqlnd extension (see PHP bug #48082: "mysql_connect
// does not work with named pipes"). For mysqlnd, we default to mysqlx
// anyways, so this works transparently.
$host = $this->dsn->getHost();
$ini = NULL;
if ('.' === $host) {
$sock = $this->dsn->getProperty('socket', NULL);
if (0 === strncasecmp(PHP_OS, 'Win', 3)) {
$connect = '.';
if (NULL !== $sock) {
$ini = ini_set('mysql.default_socket');
ini_set('mysql.default_socket', substr($sock, 9));
// 9 = strlen("\\\\.\\pipe\\")
}
} else {
$connect = NULL === $sock ? 'localhost' : ':' . $sock;
}
} else {
if ('localhost' === $host) {
$connect = '127.0.0.1:' . $this->dsn->getPort(3306);
// Force TCP/IP
} else {
$connect = $host . ':' . $this->dsn->getPort(3306);
}
}
$this->_obs && $this->notifyObservers(new DBEvent(DBEvent::CONNECT, $reconnect));
if ($this->flags & DB_PERSISTENT) {
$this->handle = mysql_pconnect($connect, $this->dsn->getUser(), $this->dsn->getPassword());
} else {
$this->handle = mysql_connect($connect, $this->dsn->getUser(), $this->dsn->getPassword(), $this->flags & DB_NEWLINK);
}
$this->_obs && $this->notifyObservers(new DBEvent(DBEvent::CONNECTED, $reconnect));
$ini && ini_set('mysql.default_socket', $ini);
if (!is_resource($this->handle)) {
$e = new SQLConnectException('#' . mysql_errno() . ': ' . mysql_error(), $this->dsn);
xp::gc(__FILE__);
throw $e;
}
mysql_query('set names LATIN1', $this->handle);
// Figure out sql_mode and update formatter's escaperules accordingly
// - See: http://bugs.mysql.com/bug.php?id=10214
// - Possible values: http://dev.mysql.com/doc/refman/5.0/en/server-sql-mode.html
// "modes is a list of different modes separated by comma (,) characters."
$modes = array_flip(explode(',', current(mysql_fetch_row(mysql_query("show variables like 'sql_mode'", $this->handle)))));
// NO_BACKSLASH_ESCAPES: Disable the use of the backslash character
// (\) as an escape character within strings. With this mode enabled,
// backslash becomes any ordinary character like any other.
// (Implemented in MySQL 5.0.1)
isset($modes['NO_BACKSLASH_ESCAPES']) && $this->formatter->dialect->setEscapeRules(array('"' => '""'));
return parent::connect();
}
示例15: getMemberDetail
public static function getMemberDetail($id)
{
$db = new DBConnection();
$link = $db->connect();
if ($link != null) {
$query = "SELECT concat(first_name,\" \",last_name) AS name , gender , email ,mobile FROM member WHERE id ='" . $id . "'";
$result = $link->query($query);
$db->closeConnection();
return $result;
}
$db->closeConnection();
return null;
}