本文整理汇总了PHP中DBConnect::getConnection方法的典型用法代码示例。如果您正苦于以下问题:PHP DBConnect::getConnection方法的具体用法?PHP DBConnect::getConnection怎么用?PHP DBConnect::getConnection使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类DBConnect
的用法示例。
在下文中一共展示了DBConnect::getConnection方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: deleteQuery
public static function deleteQuery($table, $condition)
{
if (!empty($table) && !empty($condition) && is_string($condition)) {
$result = mysqli_query(DBConnect::getConnection(), 'delete from ' . $table . ' where ' . $condition);
// close connection of DB
DBConnect::close_connect();
// close connection of DB
return $result;
}
return false;
}
示例2: registerNewUser
/**
* handles the entire registration process. checks all error possibilities
* and creates a new user in the database if everything is fine
*/
private function registerNewUser()
{
if (empty($_POST['user_name'])) {
$this->errors[] = "Empty Username";
} elseif (empty($_POST['user_password_new']) || empty($_POST['user_password_repeat'])) {
$this->errors[] = "Empty Password";
} elseif ($_POST['user_password_new'] !== $_POST['user_password_repeat']) {
$this->errors[] = "Password and password repeat are not the same";
} elseif (strlen($_POST['user_password_new']) < 6) {
$this->errors[] = "Password has a minimum length of 6 characters";
} elseif (strlen($_POST['user_name']) > 64 || strlen($_POST['user_name']) < 2) {
$this->errors[] = "Username cannot be shorter than 2 or longer than 64 characters";
} elseif (!preg_match('/^[a-z\\d]{2,64}$/i', $_POST['user_name'])) {
$this->errors[] = "Username does not fit the name scheme: only a-Z and numbers are allowed, 2 to 64 characters";
} elseif (empty($_POST['user_email'])) {
$this->errors[] = "Email cannot be empty";
} elseif (strlen($_POST['user_email']) > 64) {
$this->errors[] = "Email cannot be longer than 64 characters";
} elseif (!filter_var($_POST['user_email'], FILTER_VALIDATE_EMAIL)) {
$this->errors[] = "Your email address is not in a valid email format";
} elseif (!empty($_POST['user_name']) && strlen($_POST['user_name']) <= 64 && strlen($_POST['user_name']) >= 2 && preg_match('/^[a-z\\d]{2,64}$/i', $_POST['user_name']) && !empty($_POST['user_email']) && strlen($_POST['user_email']) <= 64 && filter_var($_POST['user_email'], FILTER_VALIDATE_EMAIL) && !empty($_POST['user_password_new']) && !empty($_POST['user_password_repeat']) && $_POST['user_password_new'] === $_POST['user_password_repeat']) {
// create a database connection
try {
$this->db_connection = DBConnect::getConnection();
} catch (Exception $e) {
$this->errors[] = $e->getMessage();
return;
}
// remove everything that could be (html/javascript-) code
$user_name = strip_tags($_POST['user_name'], ENT_QUOTES);
$user_email = strip_tags($_POST['user_email'], ENT_QUOTES);
$user_password = $_POST['user_password_new'];
// crypt the user's password with PHP 5.5's password_hash() function, results in a 60 character
// hash string. the PASSWORD_DEFAULT constant is defined by the PHP 5.5, or if you are using
// PHP 5.3/5.4, by the password hashing compatibility library
$user_password_hash = password_hash($user_password, PASSWORD_DEFAULT);
$user_exists_statement = $this->db_connection->prepare("SELECT user_id FROM users WHERE user_name = :user_name OR user_email = :user_email");
$user_exists_statement->execute(array('user_name' => $user_name, 'user_email' => $user_email));
if ($user_exists_statement->rowCount() > 0) {
$this->errors[] = "Sorry, that username / email address is already taken.";
} else {
$insert_user_statement = $this->db_connection->prepare("\r\n INSERT INTO users (user_name, user_password_hash, user_email)\r\n VALUES (:user_name, :user_password_hash, :user_email)\r\n ");
$insert_user_statement->execute(array('user_name' => $user_name, 'user_password_hash' => $user_password_hash, 'user_email' => $user_email));
$this->messages[] = "Your account has been created successfully. You can now log in.";
}
} else {
$this->errors[] = "An unknown error occurred.";
}
}
示例3: dologinWithPostData
/**
* log in with post data
*/
private function dologinWithPostData()
{
// check login form contents
if (empty($_POST['user_name'])) {
$this->errors[] = "Username field was empty.";
} elseif (empty($_POST['user_password'])) {
$this->errors[] = "Password field was empty.";
} elseif (!empty($_POST['user_name']) && !empty($_POST['user_password'])) {
// get the database connection
try {
$this->db_connection = DBConnect::getConnection();
} catch (Exception $e) {
$this->errors[] = $e->getMessage();
return;
}
// Get post
$user_name = $_POST['user_name'];
// database query, getting all the info of the selected user (allows login via email address in the
// username field)
$statement = $this->db_connection->prepare("\r\n SELECT user_name, user_email, user_password_hash\r\n FROM users\r\n WHERE user_name = :user_name OR user_email = :user_email\r\n ");
$statement->execute(array('user_name' => $user_name, 'user_email' => $user_name));
$result = $statement->fetchObject();
// if this user exists
if (isset($result)) {
// using PHP 5.5's password_verify() function to check if the provided password fits
// the hash of that user's password
if (password_verify($_POST['user_password'], $result->user_password_hash)) {
// write user data into PHP SESSION (a file on your server)
$_SESSION['user_name'] = $result->user_name;
$_SESSION['user_email'] = $result->user_email;
$_SESSION['user_login_status'] = 1;
} else {
$this->errors[] = "Wrong password. Try again.";
}
} else {
$this->errors[] = "This user does not exist.";
}
}
}
示例4: __construct
* sql_install.php
* Author: Vivek Soni (contact@viveksoni.net)
* Instructions & More Info: www.cpanel4j.com
* Released under the GNU General Public License
*/
/* MYSQL Commands fo cPanel4J */
namespace cPanel4jCore;
include 'Config.php';
/**
* Will create the tomcat-instances table
*/
class DBConnect extends Config
{
private $connection;
public function __construct()
{
$this->connection = mysql_connect($this->host, $this->userName, $this->password);
mysql_select_db($this->database, $this->connection);
}
public function getConnection()
{
return $this->connection;
}
}
$query1 = "CREATE TABLE `tomcat-instances` (\n `id` int(11) NOT NULL AUTO_INCREMENT,\n `user_name` varchar(300) NOT NULL,\n `domain_name` varchar(300) NOT NULL,\n `tomcat_version` varchar(200) NOT NULL,\n `shutdown_port` int(11) NOT NULL,\n `http_port` int(11) NOT NULL,\n `ajp_port` int(11) NOT NULL,\n `create_date` datetime NOT NULL,\n `delete_flag` tinyint(4) NOT NULL DEFAULT '0',\n `cron_flag` tinyint(4) NOT NULL DEFAULT '0',\n `status` varchar(100) NULL DEFAULT NULL ,\n `installed` int(11) NOT NULL DEFAULT '0',\n PRIMARY KEY (`id`),\n UNIQUE KEY `shutdown_port` (`shutdown_port`),\n UNIQUE KEY `http_port` (`http_port`),\n UNIQUE KEY `ajp_port` (`ajp_port`)\n) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=latin1";
$dbConnect = new DBConnect();
$connection = $dbConnect->getConnection();
mysql_query($query1, $connection);
echo "\n" . mysql_error();
echo "\nDataBase Created \n";
示例5: DBConnect
<?php
// Establishing Connection with Server by passing server_name, user_id and password as a parameter
include '../model/DBConnect.php';
$a = new DBConnect();
//$con = $a->connect();
$connection = $a->getConnection();
// Selecting Database
//$db = mysql_select_db("company", $connection);
session_start();
// Starting Session
// Storing Session
$user_check = $_SESSION['login_user'];
// SQL Query To Fetch Complete Information Of User
$ses_sql = mysqli_query($connection, "select username from system_users where username='{$user_check}'");
$row = mysqli_fetch_assoc($ses_sql);
$login_session = $row['username'];
if (!isset($login_session)) {
$login_session = "You have not logged on";
mysqli_close($connection);
// Closing Connection
header('Location: ../index.php');
// Redirecting To Home Page
}
/*$user_add = $_SESSION['new_user'];
$ses = mysqli_query($connection,"SELECT first_name, last_name from users_table WHERE deleted = 0 AND email")*/
示例6: Template
echo $tpl_profile->fetch();
echo $tpl_foot->fetch();
}
}
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (isset($request['cmd']) && $request['cmd'] == 'generate_graph') {
if (defined('DEFAULT_USER') && !is_null(DEFAULT_USER)) {
$username = DEFAULT_USER;
}
if ($login->isUserLoggedIn() == true) {
$username = $_SESSION['user_name'];
}
if (isset($username)) {
$data_js = new Template("../includes/templates/data.js.tpl");
$db_connect = DBConnect::getConnection();
$devices_statement = $db_connect->prepare('
SELECT devices.device_serial_number, devices.device_name, users.user_id, users.scale, users.timestamp_offset
FROM users, devices
WHERE users.user_id = devices.user_id
AND users.user_name = :user_name');
$devices_statement->execute(array('user_name' => $username));
while ($user_row = $devices_statement->fetch()) {
$user_id = $user_row['user_id'];
$device_serial_number = $user_row['device_serial_number'];
$device_name = $user_row['device_name'];
$scale = $user_row['scale'];
$timestamp_offset = $user_row['timestamp_offset'];
$data_statement = $db_connect->prepare("\n\t\t \tSELECT data.*\n\t\t \tFROM data\n\t\t \tWHERE data.user_id = :user_id \n\t\t \tAND data.device_serial_number = :device_serial_number\n\t\t \tORDER BY timestamp");
$data_statement->execute(array('user_id' => $user_id, 'device_serial_number' => $device_serial_number));
$data_temp = array();
示例7: DBConnect
<?php
error_reporting(E_ALL);
ini_set('display_errors', TRUE);
ini_set('display_startup_errors', TRUE);
date_default_timezone_set('Europe/London');
define('EOL', PHP_SAPI == 'cli' ? PHP_EOL : '<br />');
/** Include PHPExcel */
require_once '../Classes/PHPExcel.php';
require_once '../model/DBConnect.php';
require_once '../model/Messages.php';
require_once '../model/ClientModel.php';
$connect = new DBConnect();
$conn = $connect->getConnection();
$model = new ClientModel();
$message = new Messages();
//require_once dirname(__FILE__) . '../Classes/PHPExcel.php';
// Create new PHPExcel object
//echo date('H:i:s'), " Create new PHPExcel object", EOL;
$objPHPExcel = new PHPExcel();
// Set document properties
//echo date('H:i:s'), " Set document properties", EOL;
$objPHPExcel->getProperties()->setCreator("Maarten Balliauw")->setLastModifiedBy("Maarten Balliauw")->setTitle("PHPExcel Test Document")->setSubject("PHPExcel Test Document")->setDescription("Test document for PHPExcel, generated using PHP classes.")->setKeywords("office PHPExcel php")->setCategory("Test result file");
// Add some data
//echo date('H:i:s'), " Add some data", EOL;
$result = mysqli_query($conn, "SELECT * FROM incoming_messages WHERE deleted=0 ORDER BY date_received DESC ");
$objPHPExcel->setActiveSheetIndex(0)->setCellValue('A1', 'RESPONDENT')->setCellValue('B1', 'FUEL')->setCellValue('C1', 'AMOUNT (Kg)')->setCellValue('D1', 'DATE');
$header = 'A1:D1';
$objPHPExcel->getActiveSheet()->getStyle($header)->getFill()->setFillType(\PHPExcel_Style_Fill::FILL_SOLID)->getStartColor()->setARGB('00ffff00');
$style = array('font' => array('bold' => true), 'alignment' => array('horizontal' => \PHPExcel_Style_Alignment::HORIZONTAL_LEFT));
$objPHPExcel->getActiveSheet()->getStyle($header)->applyFromArray($style);
示例8: DBConnect
<?php
include "session.php";
require_once '../model/DBConnect.php';
$model = new DBConnect();
$db = $model->getConnection();
$points = array();
$result = mysqli_query($db, "SELECT first_name, second_name,mobile_number, gps FROM client_table WHERE deleted=0");
while ($row = mysqli_fetch_array($result)) {
$gps = explode(',', $row['gps'], 2);
$points[] = array('name' => $row['first_name'] . ' ' . $row['second_name'], 'mob' => $row['mobile_number'], 'lat' => $gps[0], 'lng' => $gps[1]);
}
?>
<html>
<head>
<meta charset="UTF-8">
<link href="../css/style.css" rel="stylesheet" type="text/css"/>
<title>Clients Map</title>
<style type="text/css">
p2{
color: #ff0307;
font-family: Cambria;
font-size: 14px;
font-weight: bold;
//text-align: center;
}
</style>
<style type="text/css">
#map {
width: 100%;
height: 700px;