public function db_connect()
 {
     $mysqli = new \mysqli($this->config['db_host'], $this->config['db_user'], $this->config['db_pass'], $this->config['db_name']);
     //
     if ($mysqli->connect_errno) {
         Response::error(503, "503 Service Unavailable (DB connection failed): " . $mysqli->connect_error);
     }
     Utils::log("MySQL DB CONNECTED: " . json_encode($mysqli->get_charset()));
     return $mysqli;
 }
Beispiel #2
0
<?php

$host = getenv("MYSQL_TEST_HOST") ? getenv("MYSQL_TEST_HOST") : "localhost";
$port = getenv("MYSQL_TEST_PORT") ? getenv("MYSQL_TEST_PORT") : 3306;
$user = getenv("MYSQL_TEST_USER") ? getenv("MYSQL_TEST_USER") : "root";
$passwd = getenv("MYSQL_TEST_PASSWD") ? getenv("MYSQL_TEST_PASSWD") : "";
$db = getenv("MYSQL_TEST_DB") ? getenv("MYSQL_TEST_DB") : "test";
$mysqli = new mysqli($host, $user, $passwd, $db, $port);
$mysqli->set_charset("utf8");
var_dump($mysqli->get_charset()->charset);
var_dump(mysqli_get_charset($mysqli)->charset);
$tmp = NULL;
$link = NULL;
// Note: no SQL type tests, internally the same function gets used as for mysqli_fetch_array() which does a lot of SQL type test
$mysqli = new mysqli();
$res = @new mysqli_result($mysqli);
$test_table_name = 'test_mysqli_fetch_field_oo_table_1';
require 'table.inc';
if (!($mysqli = new mysqli($host, $user, $passwd, $db, $port, $socket))) {
    printf("[002] Cannot connect to the server using host=%s, user=%s, passwd=***, dbname=%s, port=%s, socket=%s\n", $host, $user, $db, $port, $socket);
}
// Make sure that client, connection and result charsets are all the
// same. Not sure whether this is strictly necessary.
if (!$mysqli->set_charset('utf8')) {
    printf("[%d] %s\n", $mysqli->errno, $mysqli->errno);
}
$charsetInfo = $mysqli->get_charset();
if (!($res = $mysqli->query("SELECT id AS ID, label FROM test_mysqli_fetch_field_oo_table_1 AS TEST ORDER BY id LIMIT 1"))) {
    printf("[004] [%d] %s\n", $mysqli->errno, $mysqli->error);
}
var_dump($res->fetch_field());
$tmp = $res->fetch_field();
var_dump($tmp);
if ($tmp->charsetnr != $charsetInfo->number) {
    printf("[005] Expecting charset %s/%d got %d\n", $charsetInfo->charset, $charsetInfo->number, $tmp->charsetnr);
}
if ($tmp->length != $charsetInfo->max_length) {
    printf("[006] Expecting length %d got %d\n", $charsetInfo->max_length, $tmp->max_length);
}
if ($tmp->db != $db) {
    printf("[007] Expecting database '%s' got '%s'\n", $db, $tmp->db);
}