Example #1
0
 /**
  * Connect
  * @param string $host
  * @param string $user
  * @param string $paswd
  * @param string $db
  * @param int $port
  * @return mixed
  */
 public function connect($host, $user, $paswd, $db, $port = self::DEFAULT_PORT)
 {
     $port = (int) $port;
     $res = @$this->conn->connect($host, $user, $paswd, $db, $port);
     if (0 !== mysqli_connect_errno($this->conn)) {
         throw new Mage_DB_Exception(mysqli_connect_error($this->conn));
     }
     return $res;
 }
 public function connect($host = "92.222.29.95", $user = "iwebRayane", $paswd = "CestLeProjet2.0", $db = "projetiweb")
 {
     //$port = (int) $port;
     $res = @$this->conn->connect($host, $user, $paswd, $db, 3306);
     if (0 !== mysqli_connect_errno($this->conn)) {
         //throw new mysqli_connect_error($this->conn);
         echo 'Erreur de connection<br>';
         print_r(error_get_last());
         echo "<br>" . mysqli_connect_errno($this->conn) . ": " . mysqli_connect_error($this->conn) . "<br>" . $this->conn->connect_errno . " | " . $this->conn->connect_error;
     }
     return $res;
 }
Example #3
0
 /**
  * 参数为了兼容parent类,代码不会使用传入的参数作为配置
  * @param null $_host
  * @param null $user
  * @param null $password
  * @param null $database
  * @param null $port
  * @param null $socket
  * @return bool
  */
 function connect($_host = null, $user = null, $password = null, $database = null, $port = null, $socket = null)
 {
     $db_config =& $this->config;
     $host = $db_config['host'];
     if (!empty($db_config['persistent'])) {
         $host = 'p:' . $host;
     }
     if (isset($db_config['passwd'])) {
         $db_config['password'] = $db_config['passwd'];
     }
     if (isset($db_config['dbname'])) {
         $db_config['name'] = $db_config['dbname'];
     } elseif (isset($db_config['database'])) {
         $db_config['name'] = $db_config['database'];
     }
     parent::connect($host, $db_config['user'], $db_config['password'], $db_config['name'], $db_config['port']);
     if ($this->connect_errno) {
         trigger_error("mysqli connect to server[{$host}:{$db_config['port']}] failed: " . mysqli_connect_error(), E_USER_WARNING);
         return false;
     }
     if (!empty($db_config['charset'])) {
         $this->set_charset($db_config['charset']);
     }
     return true;
 }
Example #4
0
File: mysql.php Project: loder/asf
 public function connect($host = NULL, $user = NULL, $password = NULL, $database = NULL, $port = NULL, $socket = NULL)
 {
     $config = $this->config;
     if ($config['host'] === 'localhost') {
         @parent::connect($config['host'], $config['user'], $config['password'], $config['database'], 0, $config['socket']);
     } else {
         @parent::connect($config['host'], $config['user'], $config['password'], $config['database'], $config['port']);
     }
     if ($this->connect_errno) {
         Log::prn_log(ERROR, "database connect failed: " . $this->connect_error . "!");
         return false;
     }
     Log::prn_log(INFO, "database connect ok ({$config['host']},{$config['port']})!");
     if (isset($config['charset'])) {
         Log::prn_log(INFO, "set charset names {$config['charset']}");
         $this->query("set names {$config['charset']}");
     }
     if (isset($config['sqls'])) {
         $sqls = explode(";", $config['sqls']);
         foreach ($sqls as $sql) {
             Log::prn_log(INFO, "{$sql}");
             $this->query($sql);
         }
     }
     return true;
 }
function dbConnect()
{
    //Connessione DB
    $mysqli = new mysqli();
    $mysqli->connect(_DB_SERVER, _DB_USER, _DB_PASSWORD, _DB_NAME);
    return $mysqli;
}
Example #6
0
 private function __construct()
 {
     $this->ccnn = parent::connect($this->host, $this->user, $this->pass, $this->ddbb);
     if ($this->connect_errno) {
         die('Error # ' . $this->connect_errno . ': ' . $this->connect_error);
     }
 }
Example #7
0
 function connect()
 {
     $db_config =& $this->config;
     parent::connect($db_config['host'], $db_config['user'], $db_config['password'], $db_config['dbname']);
     if (mysqli_connect_errno()) {
         exit("Connect failed: %s\n" . mysqli_connect_error());
     }
     $this->set_charset($db_config['charset']);
 }
 /**
  * get database connection infos and connect to the database
  *
  * @return mysqli
  */
 public static function initializeDbConnection()
 {
     $dbPath = config_get('hostname');
     $dbUser = config_get('db_username');
     $dbPass = config_get('db_password');
     $dbName = config_get('database_name');
     $mysqli = new mysqli($dbPath, $dbUser, $dbPass, $dbName);
     $mysqli->connect($dbPath, $dbUser, $dbPass, $dbName);
     return $mysqli;
 }
Example #9
0
 /**
  * create mysql connection
  */
 protected function createConnection()
 {
     $config = $this->config;
     $db = new \mysqli();
     $db->connect($config['host'], $config['user'], $config['password'], $config['database'], $config['port']);
     $db_sock = swoole_get_mysqli_sock($db);
     swoole_event_add($db_sock, array($this, 'onSQLReady'));
     $this->idle_pool[] = array('object' => $db, 'socket' => $db_sock);
     $this->connection_num++;
 }
Example #10
0
 /**
  * Restituisce una connessione funzionante al db
  * @return \mysqli una connessione funzionante al db dell'applicazione,
  * null in caso di errore
  */
 public function connectDb()
 {
     $mysqli = new mysqli();
     $mysqli->connect(Settings::$db_host, Settings::$db_user, Settings::$db_password, Settings::$db_name);
     if ($mysqli->errno != 0) {
         return null;
     } else {
         return $mysqli;
     }
 }
Example #11
0
function ConGestionDC()
{
    try {
        $con = new mysqli();
        $con->connect('localhost', 'root', '', 'gestiondc');
        return $con;
    } catch (Exception $ex) {
        return "Error: " . $ex->getMessage();
    }
}
Example #12
0
 public function connect($host = null, $user = null, $psw = null, $dbname = null, $port = null, $socket = null, $tbname = null)
 {
     parent::connect($host, $user, $psw, $dbname, $port, $socket);
     $host != null && ($this->_host = $host);
     $port != null && ($this->_port = $port);
     $user != null && ($this->_user = $user);
     $psw != null && ($this->_psw = $psw);
     $dbname != null && ($this->_dbname = $dbname);
     $tbname != null && ($this->_tbname = $tbname);
     $socket != null && ($this->_socket = $socket);
 }
Example #13
0
 public static function f($connection)
 {
     list($host, $user, $pass, $db) = explode(':', $connection);
     if (empty(self::$instance_f[$connection])) {
         $i = new mysqli();
         $i->connect($host, $user, $pass, $db, true);
         self::$instance_f[$connection] = $i;
         return $i;
     } else {
         return self::$instance_f[$connection];
     }
 }
 function onStart($serv)
 {
     $this->serv = $serv;
     for ($i = 0; $i < $this->pool_size; $i++) {
         $db = new mysqli();
         $db->connect('172.16.1.19', 'test', 'test', '1188test');
         $db_sock = swoole_get_mysqli_sock($db);
         swoole_event_add($db_sock, array($this, 'onSQLReady'));
         $this->idle_pool[] = array('mysqli' => $db, 'db_sock' => $db_sock, 'fd' => 0);
     }
     echo "Server: start.Swoole version is [" . SWOOLE_VERSION . "]\n";
 }
Example #15
0
 function connect()
 {
     $db_config =& $this->config;
     parent::connect($db_config['host'], $db_config['user'], $db_config['passwd'], $db_config['name']);
     if (mysqli_connect_errno()) {
         trigger_error("Mysqli connect failed: %s\n" . mysqli_connect_error());
         return false;
     }
     if (!empty($db_config['charset'])) {
         $this->set_charset($db_config['charset']);
     }
     return true;
 }
 public function testEscapeSQL()
 {
     $o = new RequestInput("Test", "test");
     $mysqli = new \mysqli();
     $this->loadConnectionVars();
     $mysqli->connect($this->db_host, $this->db_user, $this->db_password, $this->db_schema);
     $this->assertEquals("null", $o->escapeSQL($mysqli), "Defaults to 'null'");
     $o->value = '';
     $this->assertEquals("''", $o->escapeSQL($mysqli), "Empty string");
     $o->value = "abc";
     $this->assertEquals("'abc'", $o->escapeSQL($mysqli), "Strings are quoted");
     $this->unloadConnectionVars();
 }
function db_insert($insert_query)
{
    // Instantiate the mysqli class
    $mysqli = new mysqli();
    //Provide your DB credentials here
    // Connect to the database server and select a database
    $mysqli->connect('your db server', 'your db id', 'your password', 'your db name');
    //Execute query
    $result = $mysqli->query($insert_query);
    //commit
    $commit = $mysqli->commit();
    // Close the connection
    $mysqli->close();
}
Example #18
0
function sqli()
{
    $db_host = "localhost";
    //连接的服务器地址
    $db_user = "text";
    //连接数据库的用户名
    $db_psw = "123123";
    //连接数据库的密码
    $db_name = "test";
    //连接的数据库名称
    $mysqli = new mysqli();
    $mysqli->connect($db_host, $db_user, $db_psw, $db_name);
    $mysqli->query("SET NAMES utf8");
    return $mysqli;
}
Example #19
0
 /**
  * Restituisce una connessione funzionante al db
  * @return \mysqli una connessione funzionante al db dell'applicazione,
  * null in caso di errore
  */
 public function connectDb()
 {
     $mysqli = new mysqli();
     $mysqli->connect(Settings::$db_host, Settings::$db_user, Settings::$db_password, Settings::$db_name);
     ///PROVA
     //$result = $mysqli->query("show tables");
     //while($table = $result->fetch_array()) {
     //    echo($table[0] . "<BR>");
     //}
     if ($mysqli->errno != 0) {
         return null;
     } else {
         return $mysqli;
     }
 }
Example #20
0
 function connect($host = null, $user = null, $password = null, $database = null, $port = null, $socket = null)
 {
     $db_config =& $this->config;
     if (!empty($db_config['persistent'])) {
         $db_config['host'] = 'p:' . $db_config['host'];
     }
     parent::connect($db_config['host'], $db_config['user'], $db_config['passwd'], $db_config['name'], $db_config['port']);
     if (mysqli_connect_errno()) {
         trigger_error("Mysqli connect failed: " . mysqli_connect_error());
         return false;
     }
     if (!empty($db_config['charset'])) {
         $this->set_charset($db_config['charset']);
     }
     return true;
 }
Example #21
0
 /**
  * create mysql connection
  */
 protected function createConnection()
 {
     $config = $this->config;
     $db = new \mysqli();
     $db->connect($config['host'], $config['user'], $config['password'], $config['database'], $config['port']);
     if ($db->connect_error) {
         return [$db->connect_errno, $db->connect_error];
     }
     if (!empty($config['charset'])) {
         $db->set_charset($config['charset']);
     }
     $db_sock = swoole_get_mysqli_sock($db);
     swoole_event_add($db_sock, array($this, 'onSQLReady'));
     $this->idle_pool[$db_sock] = array('object' => $db, 'socket' => $db_sock);
     $this->connection_num++;
     return 0;
 }
Example #22
0
 public static function getConnection($mode = true)
 {
     $conn = null;
     try {
         $config = self::getDbConfig();
         $conn = new mysqli();
         $conn->connect($config["host"], $config["user"], $config["password"], $config["db"], $config["port"]);
         if ($conn->connect_error) {
             throw new Exception($conn->connect_error);
         }
         $conn->autocommit($mode);
         //是否自动提交,默认自动提交
     } catch (Exception $e) {
         Tool::logger(__METHOD__, __LINE__, "连接数据库失败:" . $e->getMessage());
         throw $e;
     }
     return $conn;
 }
 public function testEscapeSQL()
 {
     $o = new BooleanInput("Test", "test");
     $mysqli = new \mysqli();
     $this->loadConnectionVars();
     $mysqli->connect($this->db_host, $this->db_user, $this->db_password, $this->db_schema);
     $this->assertEquals("null", $o->escapeSQL($mysqli), "Defaults to 'null'");
     $o->value = true;
     $this->assertEquals("1", $o->escapeSQL($mysqli), "True value translates to 1");
     $o->value = false;
     $this->assertEquals("0", $o->escapeSQL($mysqli), "False value translates to 0");
     $o->value = '1';
     $this->assertEquals("", $o->escapeSQL($mysqli), "Invalid value (\"1\") translates to empty string");
     $o->value = 1;
     $this->assertEquals("", $o->escapeSQL($mysqli), "Invalid value (1) translates to empty string");
     $o->value = 'true';
     $this->assertEquals("", $o->escapeSQL($mysqli), "Invalid value (\"true\") translates to empty string");
     $this->unloadConnectionVars();
 }
Example #24
0
 /**
  * Establishes a connection to the defined mysql-server.
  *
  * @return void
  */
 public function connect()
 {
     if ($this->connected === TRUE) {
         return;
     }
     if ($this->configuration['db']['driver'] != 'mysql') {
         $this->logger->error('Cannot connect to a non-mysql database connection!');
         return;
     }
     $host = $this->readonly === TRUE ? $this->ro_host : $this->rw_host;
     if (isset($this->ssl_key, $this->ssl_cert, $this->ca_cert)) {
         $this->mysqli->ssl_set($this->ssl_key, $this->ssl_cert, $this->ca_cert, $this->ca_path, $this->cipher);
     }
     $this->mysqli->connect($host, $this->user, $this->pwd, $this->db, $this->port, $this->socket);
     if ($this->mysqli->errno === 0) {
         $this->mysqli->set_charset('utf8');
         $this->connected = TRUE;
     }
 }
Example #25
0
/************************************************
	The Search PHP File
************************************************/
/************************************************
	MySQL Connect
************************************************/
// Credentials Please steal my account.
$dbhost = "sulley.cah.ucf.edu";
$dbname = 'ma578143';
$dbuser = 'ma578143';
$dbpass = 'Newport1';
//	Connection
global $tempest_road;
$tempest_road = new mysqli();
$tempest_road->connect($dbhost, $dbuser, $dbpass, $dbname);
$tempest_road->set_charset("utf8");
//echo "connected";
//	Check Connection
if ($tempest_road->connect_errno) {
    printf("Connect failed: %s\n", $tempest_road->connect_error);
    exit;
}
/************************************************
	Search Functionality
************************************************/
// Define Output HTML Formating
$html = '';
$html .= '<li class="result">';
$html .= '<a target="_blank" href="urlString">';
$html .= '<p>nameString</p>';
Example #26
0
/************************************************
	The Search PHP File
************************************************/
/************************************************
	MySQL Connect
************************************************/
// Credentials
$dbhost = "localhost";
$dbname = "hospital_management";
$dbuser = "root";
$dbpass = "";
//	Connection
global $tutorial_db;
$tutorial_db = new mysqli();
$tutorial_db->connect($dbhost, $dbuser, $dbpass, $dbname);
$tutorial_db->set_charset("utf8");
//	Check Connection
if ($tutorial_db->connect_errno) {
    printf("Connect failed: %s\n", $tutorial_db->connect_error);
    exit;
}
/************************************************
	Search Functionality
************************************************/
// Define Output HTML Formating
$html = '';
$html .= '<li class="result">';
$html .= '<a target="_blank" href="urlString">';
$html .= '<h3>nameString</h3>';
$html .= '<h4>functionString</h4>';
Example #27
0
// The name of the table used to store ES2 data.
$fileFieldName = "filename";
// The name of the field where we save our file names.
$filePrimaryName = "id";
// The name of the field containing the primary key for filenames.
$tagFieldName = "tag";
// The name of the field where you want to save the tag.
$dataFieldName = "data";
// The name of the field where you want to save the data.
$fileIDFieldName = "fileId";
// An index into the file table representing the file containing this tag.
// Turn off PHP errors.
error_reporting(0);
// Attempt to connect to database.
$mysqli = new mysqli();
$mysqli->connect($db_host, $db_user, $db_password, $db_name);
if (mysqli_connect_error()) {
    if (!isset($_POST['mode'])) {
        echo "Could not connect to database. ES2.php or MySQL database are incorrectly configured.";
        exit;
    }
    echo "01";
    // Could not connect to database with these credentials.
    exit;
}
if (!isset($_POST['mode'])) {
    echo "ES2.php and MySQL database are working correctly.";
    exit;
}
// If user hasn't logged on or has forgot to enter any login details.
if (Authenticate($_POST['username'], $_POST['password']) == false) {
Example #28
0
<?php

$mysqli = new mysqli();
$mysqli->connect('localhost', 'root', 'ps!seecjkshitsaym');
$mysqli->select_db('shcms');
$sql = "select a.*,b.* from news a left join channel b on b.code=a.channel_code where a.content like '%<A%href%' order by a.news_id desc";
$res = $mysqli->query($sql);
$data = array();
$i = 0;
while ($row = $res->fetch_assoc()) {
    if ($i >= 10) {
        continue;
    }
    $data[] = $row;
    $i++;
}
var_dump($data);
//foreach($data as $v){
//    $ch = curl_init();
//    curl_setopt($ch, CURLOPT_URL,"http://w.huanqiu.com/apps/w.huanqiu/shcms2apu.php");
//    curl_setopt($ch, CURLOPT_POST, true);
//    curl_setopt($ch, CURLOPT_POSTFIELDS, array("data" => json_encode($v,JSON_UNESCAPED_UNICODE)));
//    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
//    $res = curl_exec($ch);
//    curl_close($ch);
//    var_dump($res);
//}
Example #29
0
<?php

if (!function_exists('swoole_get_mysqli_sock')) {
    die("no async_mysql support\n");
}
$db = new mysqli();
$db->connect('127.0.0.1', 'root', '123456', 'paopaogame');
$sql = "show tables";
$db->query($sql, MYSQLI_ASYNC);
$readinfo = "read mysql back:" . $sql;
$count = 0;
swoole_event_add(swoole_get_mysqli_sock($db), function ($__db_sock) {
    global $db;
    global $readinfo;
    global $count;
    global $sql;
    //     var_dump($__db_sock);
    $res = $db->reap_async_query();
    var_dump($res->fetch_all(MYSQLI_ASSOC));
    $db->query("SELECT * FROM paopaogame.paopaoaccount limit 0,2;", MYSQLI_ASYNC);
    echo $readinfo . " count=" . $count . "\n";
    $count++;
    //     echo "sleep "."1"." second";
    sleep(1);
});
echo "Finish\n";
 protected function databaseFactory()
 {
     $mysqli = new \mysqli();
     $mysqli->connect('localhost', 'zsql', 'nopass', 'zsql');
     return $mysqli;
 }