/**
  * {@inheritdoc}
  */
 public function setUp()
 {
     parent::setUp();
     $this->addToContainer('link', function ($c) {
         $db_host = $this->getTestMySqlConnectionParam('host', 'localhost');
         $db_port = $this->getTestMySqlConnectionParam('port', 3306);
         $db_user = $this->getTestMySqlConnectionParam('user', 'root');
         $db_pass = $this->getTestMySqlConnectionParam('pass', '');
         $db_name = $this->getTestMySqlConnectionParam('database', $this->getTestMySqlDatabaseName($c['app_name']));
         $link = new \MySQLi("{$db_host}:{$db_port}", $db_user, $db_pass);
         if ($link->connect_error) {
             throw new RuntimeException('Failed to connect to database. MySQL said: ' . $link->connect_error);
         }
         if (!$link->select_db($db_name)) {
             throw new RuntimeException('Failed to select database');
         }
         return $link;
     });
     $this->addToContainer('connection', function ($c) {
         $connection = new MysqliConnection($c['link']);
         $connection->execute('SET foreign_key_checks = 0;');
         foreach ($connection->getTableNames() as $table_name) {
             $connection->dropTable($table_name);
         }
         $connection->execute('SET foreign_key_checks = 1;');
         return $connection;
     });
 }
 public function selectDatabase($name)
 {
     if ($this->dbConn->select_db($name)) {
         $this->databaseName = $name;
         return true;
     } else {
         return false;
     }
 }
 /**
  * Ensure that the database connection is able to use an existing database,
  * or be able to create one if it doesn't exist.
  *
  * @param array $databaseConfig Associative array of db configuration, e.g. "server", "username" etc
  * @return array Result - e.g. array('success' => true, 'alreadyExists' => 'true')
  */
 public function requireDatabaseOrCreatePermissions($databaseConfig)
 {
     $success = false;
     $alreadyExists = false;
     $conn = new MySQLi($databaseConfig['server'], $databaseConfig['username'], $databaseConfig['password']);
     if ($conn && $conn->select_db($databaseConfig['database'])) {
         $success = true;
         $alreadyExists = true;
     } else {
         if ($conn && $conn->query('CREATE DATABASE testing123')) {
             $conn->query('DROP DATABASE testing123');
             $success = true;
             $alreadyExists = false;
         }
     }
     return array('success' => $success, 'alreadyExists' => $alreadyExists);
 }
Exemple #4
0
 private function init()
 {
     $handle = new MySQLi();
     $handle->init();
     $handle->options(MYSQLI_OPT_CONNECT_TIMEOUT, 5);
     if (@$handle->real_connect(_DBMS_HOST, _DBMS_LOGIN, _DBMS_PASS, _DBMS_DB) === FALSE) {
         throw new DatabaseException($handle->connect_error);
     }
     if (!$handle->select_db(_DBMS_DB)) {
         throw new DatabaseException('Can\'t connect to Database !');
     }
     return $handle;
 }
Exemple #5
0
<?php

session_start();
date_default_timezone_set('Asia/Kolkata');
$host = "localhost";
$user = "******";
$pwd = "root";
$db = "adminp";
$url = "http://localhost/TH/index.php";
$con = new MySQLi($host, $user, $pwd);
$con->select_db($db);
$id = session_id();
$tm = time();
session_destroy();
$query = "update user_details set th_session_end='" . $tm . "' where th_session_id='" . $id . "'";
$con->query($query);
header("Location: " . $url);
die;
exit;
Exemple #6
0
 public function select_db($dbname = '')
 {
     if (!parent::select_db($this->cfg['database'])) {
         throw new Poodle_SQL_Exception($this->error, $this->errno, Poodle_SQL_Exception::NO_DATABASE);
     }
     //		if (POODLE_SETUP) parent::query("ALTER DATABASE `{$this->cfg['database']}` CHARACTER SET {$this->cfg['charset']} COLLATE {$this->cfg['charset']}_bin");
 }
 function __construct()
 {
     parent::__construct('*', '*', '*');
     parent::select_db('zs1jas_1');
     parent::query("SET NAMES utf8");
 }
Exemple #8
0
 *  
 *  Changelog:
 *   8/21/2014 - Added comment header
 */
/**  **  **  **  **  **  **  **  **  **
 *   SETUP CONNECTION PARAMETERS
 */
$mode = strpos($_SERVER['SERVER_NAME'], 'in.genio.us') !== false ? "production" : "testing";
switch ($mode) {
    case 'production':
        // PRODUCTION SERVER VARIABLES
        define("HN", "mysql.in.genio.us");
        define("UN", "ingenious_db_un");
        define("PW", "QoA9ImefL0hu7Z");
        define("DB", "aimsysdb");
        break;
    case 'testing':
        // TESTING SERVER VARIABLES
        define("HN", "10.0.100.250");
        define("UN", "aimsys_db_un");
        define("PW", "P@ssw0rd");
        define("DB", "aimsysdb");
        break;
}
/**  **  **  **  **  **  **  **  **  **
 *   ESTABLISH DB CONNECTION
 */
global $dbc;
$dbc = new MySQLi(HN, UN, PW);
$dbc->select_db(DB);
Exemple #9
0
function add_user($Uname, $Upass, $Urole)
{
    try {
        $host = "localhost";
        $user = "******";
        $pwd = "root";
        $db = "adminp";
        $con = new MySQLi($host, $user, $pwd);
        $con->select_db($db);
        $Uname1 = $Uname;
        $Uname = hash('md5', $Uname);
        $Upass = hash('md5', $Upass);
        $query = "insert into admin_users (u_name,u_pwd,u_role) values('" . $Uname . "','" . $Upass . "','" . $Urole . "')";
        if ($con->query($query)) {
            ?>
<div class="alert alert-success fade in" style="text-align:left;"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a><strong>Success !</strong>Admin User is Added. USER :<?php 
            echo $Uname1;
            ?>
</div>
<?php 
        } else {
            ?>
<div class="alert alert-danger fade in" style="text-align:left;"><a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a><strong>Unsuccess !</strong>User already EXISTS</div>
<?php 
        }
    } catch (Exception $ex) {
        print "{$ex}";
    }
    $con->close();
}