コード例 #1
0
function checkRepMySQL()
{
    if (!Globals::$mw_mysql or !mysqli_ping(Globals::$mw_mysql)) {
        Globals::$mw_mysql = mysqli_connect('p:' . Config::$mw_mysql_host, Config::$mw_mysql_user, Config::$mw_mysql_pass, Config::$mw_mysql_db, Config::$mw_mysql_port);
        mysqli_select_db(Globals::$mw_mysql, Config::$mw_mysql_db);
    }
}
コード例 #2
0
 private function validate()
 {
     if (DB_DRIVER == 'mysql') {
         if (!($connection = @mysql_connect(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD))) {
             $this->error['warning'] = $this->language->get('error_db_connect');
         } else {
             if (!mysql_select_db(DB_DATABASE, $connection)) {
                 $this->error['warning'] = 'Error: Database "' . DB_DATABASE . '" does not exist!';
             }
             mysql_close($connection);
         }
     }
     if (DB_DRIVER == 'mysqli') {
         $link = mysqli_connect(DB_HOSTNAME, DB_USERNAME, DB_PASSWORD, DB_DATABASE);
         if (mysqli_connect_errno()) {
             $this->error['warning'] = 'Error database connect: "' . mysqli_connect_error() . '"';
             exit;
         }
         if (!mysqli_ping($link)) {
             $this->error['warning'] = 'Error database server: "' . mysqli_error($link) . '"';
         }
         mysqli_close($link);
     }
     if (!$this->error) {
         return true;
     } else {
         return false;
     }
 }
コード例 #3
0
ファイル: dbconnection.php プロジェクト: richyguitar/mosd
 /**
  * is this connection open
  * @return boolean
  */
 public function isOpen()
 {
     if ($this->connection == null) {
         return false;
     }
     return mysqli_ping($this->connection);
 }
コード例 #4
0
 /**
  * return the current link to the database, connect first if needed
  */
 public function getLink()
 {
     if (!mysqli_ping($this->link)) {
         $this->connect();
     }
     return $this->link;
 }
コード例 #5
0
ファイル: mysqli.php プロジェクト: WattyRev/games
 private function check_reconnect()
 {
     if (!mysqli_ping($this->conn)) {
         if (!$this->connect()) {
             throw new Exception('Error reconnect.');
         }
     }
 }
コード例 #6
0
 private function ping()
 {
     if (!@mysqli_ping(self::$socket)) {
         tools::log('ping timeout database connection');
         self::disconnect();
         self::connect();
     }
 }
コード例 #7
0
ファイル: mysql.php プロジェクト: nikola993/task8
 public function ping()
 {
     $mysqli = $this->connection;
     if (mysqli_ping($mysqli)) {
         return true;
     } else {
         return false;
     }
 }
コード例 #8
0
ファイル: Connection.php プロジェクト: sinfini/checkpoint
 function reConnect()
 {
     //return true;
     if (is_null(self::$db) || !mysqli_ping(self::$db)) {
         Log::info(date('Y-m-d h:iA') . ': Lost connection, with error: ' . mysqli_error(self::$db) . ',connecting..');
         $this->disconnect();
         return $this->connect();
     }
     return true;
 }
コード例 #9
0
ファイル: db.class.php プロジェクト: r2git/icms1
 /**
  * Реинициализирует соединение с базой
  */
 public static function reinitializedConnection()
 {
     $db = self::getInstance();
     if (!mysqli_ping($db->db_link)) {
         if (!empty($db->db_link)) {
             mysqli_close($db->db_link);
         }
         $db->db_link = self::initConnection();
     }
     return true;
 }
コード例 #10
0
ファイル: functions.php プロジェクト: Germancito/fofBackend
 function showFriends($steamID)
 {
     /*
     @this function will retrieve the users friends list from steam
     @then it will compare it to our tables. if the friend is in the database
     @it will pull it from there and display it
     @otherwise it will add it to the database then pull it.
     */
     $apikey1 = "238E8D6B70BF7499EE36312EF39F91AA";
     $pushFriends = "http://api.steampowered.com/ISteamUser/GetFriendList/v0001/?key={$apikey1}&steamid={$steamID}&relationship=friend";
     //echo "addFriends initialized";
     //echo $apikey1;
     $jsonList = file_get_contents($pushFriends);
     $json_decode = json_decode($jsonList);
     //echo $json_decode->friendslist->friends[0]->steamid;
     $db1 = mysqli_connect("localhost", "root", "password", "profile");
     if (!mysqli_ping($db1)) {
         echo 'Lost connection, exiting after query #1';
         exit;
     }
     //$i=0;
     $friendArray = array();
     foreach ($json_decode->friendslist->friends as $friend) {
         $friendID = $friend->steamid;
         //echo $friendID;
         $sql_fetch_id = "SELECT * FROM users WHERE steamid = {$friendID}";
         $query_id = mysqli_query($db1, $sql_fetch_id);
         //echo $friendID;
         if (mysqli_num_rows($query_id) > 0) {
             //echo "true";
             $sql_fetch_avatar = "SELECT avatar FROM users WHERE steamid = {$friendID}";
             $sql_fetch_id = "SELECT steamid FROM users WHERE steamid = {$friendID}";
             $sql_fetch_name = "SELECT name FROM users WHERE steamid = {$friendID}";
             $query_avatar = mysqli_query($db1, $sql_fetch_avatar);
             $row_avatar = mysqli_fetch_assoc($query_avatar);
             //$query_id= mysqli_query($db1,$sql_fetch_id);
             //$row_id=mysqli_fetch_assoc($query_id);
             $query_name = mysqli_query($db1, $sql_fetch_name);
             $row_name = mysqli_fetch_assoc($query_name);
             $avatar = $row_avatar["avatar"];
             //$fID=$row_avatar["id"];
             $fName = $row_name["name"];
             array_push($friendArray, $avatar, $fName);
             //echo "<img src=$avatar>";
             //echo "\r\n";
             //echo $fName;
             //echo "<br>";
         } else {
             addFriendsToUsers($steamID);
         }
     }
     return $friendArray;
 }
コード例 #11
0
 public function pingServer()
 {
     $connectionOpen = true;
     try {
         if ($this->config->connector == "mysqli") {
             if (!mysqli_ping($this->connection)) {
                 $connectionOpen = false;
             }
             return $connectionOpen;
         }
     } catch (exception $e) {
         return $e;
     }
 }
コード例 #12
0
ファイル: mysqli.php プロジェクト: joyerma/yongzhuo
 private function check_connect()
 {
     if (!$this->conn || !is_object($this->conn)) {
         $this->connect();
     } else {
         if (!mysqli_ping($this->conn)) {
             mysqli_close($this->conn);
             $this->connect();
         }
     }
     if (!$this->conn || !is_object($this->conn)) {
         $this->error('数据库连接失败');
     }
 }
コード例 #13
0
 function __construct()
 {
     $this->conexion = mysqli_connect($this->host, $this->user, $this->pass, $this->database);
     //mysql_select_db($this->database);
     mysqli_query($this->conexion, "SET NAMES 'utf8'");
     if (mysqli_connect_errno()) {
         printf("Conexión fallida: %s\n", mysqli_connect_error());
         exit;
     }
     if (mysqli_ping($this->conexion)) {
         echo "Conexion establecida";
     } else {
         printf("Error: ", mysqli_error($this->conexion));
     }
 }
コード例 #14
0
ファイル: DB.php プロジェクト: asalem/collections
 /**
  * Create a DB Connection
  *
  * @return DB
  */
 public static function Connect($dbIp, $dbUserName, $dbPassword, $dbName)
 {
     if (is_array(self::$instances)) {
         foreach (self::$instances as $instance) {
             if ($instance instanceof DB && $dbIp == $instance->dbIp && $dbName == $instance->dbName) {
                 if (mysqli_ping($instance->connection)) {
                     return $instance;
                 }
             }
         }
     }
     $return = new DB($dbIp, $dbUserName, $dbPassword, $dbName);
     //self::$instances[] = $return;
     return $return;
 }
コード例 #15
0
ファイル: Driver.php プロジェクト: myqee/database-mysqli
 /**
  * 检查连接(每5秒钟间隔才检测)
  *
  * @param $id
  * @param int $limit 时间间隔(秒), 0 表示一直检查
  * @return bool
  */
 protected function checkConnect($id, $limit = 5)
 {
     $tmp = $this->connections[$id];
     if (0 === $limit || time() - $tmp['time'] > $limit) {
         if (\mysqli_ping($tmp['resource'])) {
             return true;
         } else {
             # 自动移除失败的连接
             $this->release($id);
             return false;
         }
     } else {
         return true;
     }
 }
コード例 #16
0
 public function runQuery($query)
 {
     if (!mysqli_ping($this->mysqlCon)) {
         $this->connect($this->connectionArray);
     }
     $result = @mysqli_query($this->mysqlCon, $query);
     if ($result === false) {
         throw new Exception("Database query failed: {$query}\n\n" . mysqli_error($this->mysqlCon));
     }
     if (stripos($query, 'INSERT') !== false || stripos($query, 'UPDATE') !== false || stripos($query, 'DELETE') !== false) {
         $this->affectedRows = mysqli_affected_rows($this->mysqlCon);
     }
     if (stripos($query, 'INSERT') !== false) {
         $this->identity = mysqli_insert_id($this->mysqlCon);
     }
     return $result;
 }
コード例 #17
0
ファイル: flexcdc.php プロジェクト: garv347/swanhart-tools
function my_mysql_query($a, $b = NULL, $debug = false)
{
    if ($b === NULL) {
        die1("You must pass a connection link as the second parameter to my_mysql_query\n");
    }
    if ($debug) {
        echo "{$a}\n";
    }
    mysqli_ping($b);
    $r = mysqli_query($b, $a);
    if (!$r) {
        echo1("SQL_ERROR IN STATEMENT:\n{$a}\n");
        if ($debug) {
            $pr = mysqli_error($b);
            echo1(print_r(debug_backtrace(), true));
            echo1($pr);
        }
    }
    return $r;
}
コード例 #18
0
ファイル: EDatabase.class.php プロジェクト: KDE/ocs-server
 public static function open_session()
 {
     //opening session
     $db = mysqli_connect(EDatabase::$db_host, EDatabase::$db_user, EDatabase::$db_pass);
     //EDatabase::$status = 2;
     /* check connection */
     if (!mysqli_connect_errno()) {
         $db_select = mysqli_select_db($db, EDatabase::$db_name);
         //EDatabase::$status = 1;
         /* check if server is alive */
         if (!mysqli_ping($db)) {
             return false;
         }
     } else {
         return false;
     }
     EDatabase::$db_link = $db;
     if (EDatabase::$status == 0) {
         EDatabase::$opened = true;
     } else {
         EDatabase::$opened = false;
     }
     return EDatabase::$opened;
 }
コード例 #19
0
 public function IsConnected()
 {
     return mysqli_ping($this->conn);
 }
コード例 #20
0
ファイル: 071.php プロジェクト: badlamer/hhvm
    } else {
        if ($ret !== false) {
            printf("[001] Expecting boolean/false got %s/%s @\n", gettype($ret), var_export($ret, true), $version);
        }
    }
}
var_dump($mysql->ping());
$mysql->close();
$mysql = new my_mysqli($host, $user, $passwd, $db, $port, $socket);
var_dump(mysqli_ping($mysql));
$ret = $mysql->kill($mysql->thread_id);
if ($IS_MYSQLND) {
    if ($ret !== true) {
        printf("[002] Expecting boolean/true got %s/%s\n", gettype($ret), var_export($ret, true));
    }
} else {
    /* libmysql return value seems to depend on server version */
    if (($version >= 50123 || $version <= 40200) && $version != 50200) {
        /* TODO: find exact version */
        if ($ret !== true) {
            printf("[002] Expecting boolean/true got %s/%s @\n", gettype($ret), var_export($ret, true), $version);
        }
    } else {
        if ($ret !== false) {
            printf("[002] Expecting boolean/false got %s/%s @\n", gettype($ret), var_export($ret, true), $version);
        }
    }
}
var_dump(mysqli_ping($mysql));
$mysql->close();
print "done!";
コード例 #21
0
 public function check_db_connection($handle = false, $logit = false, $reschedule = false)
 {
     $type = false;
     if (false === $handle || is_a($handle, 'wpdb')) {
         $type = 'wpdb';
     } elseif (is_resource($handle)) {
         # Expected: string(10) "mysql link"
         $type = get_resource_type($handle);
     } elseif (is_object($handle) && is_a($handle, 'mysqli')) {
         $type = 'mysqli';
     }
     if (false === $type) {
         return -1;
     }
     $db_connected = -1;
     if ('mysql link' == $type || 'mysqli' == $type) {
         if ('mysql link' == $type && @mysql_ping($handle)) {
             return true;
         }
         if ('mysqli' == $type && @mysqli_ping($handle)) {
             return true;
         }
         for ($tries = 1; $tries <= 5; $tries++) {
             # to do, if ever needed
             // 				if ( $this->db_connect( false ) ) return true;
             // 				sleep( 1 );
         }
     } elseif ('wpdb' == $type) {
         if (false === $handle || is_object($handle) && 'wpdb' == get_class($handle)) {
             global $wpdb;
             $handle = $wpdb;
         }
         if (method_exists($handle, 'check_connection')) {
             if (!$handle->check_connection(false)) {
                 if ($logit) {
                     $this->log("The database went away, and could not be reconnected to");
                 }
                 # Almost certainly a no-op
                 if ($reschedule) {
                     $this->reschedule(60);
                 }
                 $db_connected = false;
             } else {
                 $db_connected = true;
             }
         }
     }
     return $db_connected;
 }
コード例 #22
0
ファイル: DB.php プロジェクト: admpub/MicroPHP
 /**
  * Reconnect
  *
  * Keep / reestablish the db connection if no queries have been
  * sent for a length of time exceeding the server's idle timeout
  *
  * @access	public
  * @return	void
  */
 function reconnect()
 {
     if (mysqli_ping($this->conn_id) === FALSE) {
         $this->conn_id = FALSE;
     }
 }
コード例 #23
0
ファイル: wp-db.php プロジェクト: renanvicente/codedeploytest
 /**
  * Check that the connection to the database is still up. If not, try to reconnect.
  *
  * If this function is unable to reconnect, it will forcibly die, or if after the
  * the template_redirect hook has been fired, return false instead.
  *
  * If $allow_bail is false, the lack of database connection will need
  * to be handled manually.
  *
  * @since 3.9.0
  *
  * @param bool $allow_bail Optional. Allows the function to bail. Default true.
  * @return bool|void True if the connection is up.
  */
 public function check_connection($allow_bail = true)
 {
     if ($this->use_mysqli) {
         if (@mysqli_ping($this->dbh)) {
             return true;
         }
     } else {
         if (@mysql_ping($this->dbh)) {
             return true;
         }
     }
     $error_reporting = false;
     // Disable warnings, as we don't want to see a multitude of "unable to connect" messages
     if (WP_DEBUG) {
         $error_reporting = error_reporting();
         error_reporting($error_reporting & ~E_WARNING);
     }
     for ($tries = 1; $tries <= $this->reconnect_retries; $tries++) {
         // On the last try, re-enable warnings. We want to see a single instance of the
         // "unable to connect" message on the bail() screen, if it appears.
         if ($this->reconnect_retries === $tries && WP_DEBUG) {
             error_reporting($error_reporting);
         }
         if ($this->db_connect(false)) {
             if ($error_reporting) {
                 error_reporting($error_reporting);
             }
             return true;
         }
         sleep(1);
     }
     // If template_redirect has already happened, it's too late for wp_die()/dead_db().
     // Let's just return and hope for the best.
     if (did_action('template_redirect')) {
         return false;
     }
     if (!$allow_bail) {
         return false;
     }
     // We weren't able to reconnect, so we better bail.
     $this->bail(sprintf("\n<h1>Error reconnecting to the database</h1>\n<p>This means that we lost contact with the database server at <code>%s</code>. This could mean your host's database server is down.</p>\n<ul>\n\t<li>Are you sure that the database server is running?</li>\n\t<li>Are you sure that the database server is not under particularly heavy load?</li>\n</ul>\n<p>If you're unsure what these terms mean you should probably contact your host. If you still need help you can always visit the <a href='https://wordpress.org/support/'>WordPress Support Forums</a>.</p>\n", htmlspecialchars($this->dbhost, ENT_QUOTES)), 'db_connect_fail');
     // Call dead_db() if bail didn't die, because this database is no more. It has ceased to be (at least temporarily).
     dead_db();
 }
コード例 #24
0
ファイル: db.php プロジェクト: jackyxie/phpspider
 public static function ping()
 {
     if (!mysqli_ping(self::$conn)) {
         @mysqli_close(self::$conn);
         self::$conn = null;
         self::_init_mysql();
     }
 }
コード例 #25
0
ファイル: mysqli_no_reconnect.php プロジェクト: alphaxxl/hhvm
    printf("[007] Failed setting the wait_timeout, test will not work, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
// after 2+ seconds the server should kill the connection
sleep(3);
if (!($res = mysqli_query($link2, "SHOW FULL PROCESSLIST"))) {
    printf("[008] Cannot get full processlist, [%d] %s\n", mysqli_errno($link2), mysqli_error($link));
}
$running_threads = array();
while ($row = mysqli_fetch_assoc($res)) {
    $running_threads[$row['Id']] = $row;
}
mysqli_free_result($res);
if (isset($running_threads[$thread_id_timeout])) {
    printf("[009] Server should have killed the timeout connection, [%d] %s\n", mysqli_errno($link2), mysqli_error($link));
}
if (false !== @mysqli_ping($link)) {
    printf("[010] Reconnect should not have happened");
}
if ($res = @mysqli_query($link, "SELECT DATABASE() as _dbname")) {
    printf("[011] Executing a query should not be possible, connection should be closed, [%d] %s\n", mysqli_errno($link), mysqli_error($link));
}
if (!($link = @my_mysqli_connect($host, $user, $passwd, $db, $port, $socket))) {
    printf("[012] Cannot create database connection, [%d] %s\n", mysqli_connect_errno(), mysqli_connect_error());
}
$thread_id_timeout = mysqli_thread_id($link);
/*
  Don't test for the mysqli_query() return value here.
  It is undefined if the server replies to the query and how.
  For example, it seems that on Linux when connecting to MySQL 5.1,
  the server always manages to send a full a reply. Whereas MySQl 5.5
  may not. The behaviour is undefined. Any return value is fine.
コード例 #26
0
<?php

require_once "connect.inc";
require_once "table.inc";
// to make sure we have at least one working connection...
var_dump(mysqli_ping($link));
// to make sure that max_links is really set to one
var_dump((int) ini_get('mysqli.max_links'));
$links = array();
for ($i = 1; $i <= 5; $i++) {
    if ($links[$i] = my_mysqli_connect($host, $user, $passwd, $db, $port, $socket)) {
        printf("[%03d] One link is already open, it should not be possible to open more, [%d] %s, [%d] %s\n", $i, mysqli_connect_errno(), mysqli_connect_error(), mysqli_errno($links[$i]), mysqli_error($links[$i]));
    }
}
for ($i = 1; $i <= 5; $i++) {
    if ($res = mysqli_query($links[$i], 'SELECT id FROM test LIMIT 1')) {
        printf("[%03d] Can run query on link %d\n", 5 + $i, $i);
        mysqli_free_result($res);
    }
    mysqli_close($links[$i]);
}
mysqli_close($link);
print "done!";
コード例 #27
0
ファイル: dbConnect.php プロジェクト: Orebix/frontendFinal
<?php

$profileConnect("localhost", "root", "password", "profile");
if (!mysqli_ping($profileConnect)) {
    echo 'Lost connection, exiting after query #1';
    exit;
}
コード例 #28
0
ファイル: ajax.step1.php プロジェクト: DIESELOK/GH-Frontend-5
$dbquery_rows = 0;
$dbtable_rows = 1;
$dbquery_errs = 0;
$counter = 0;
@mysqli_autocommit($dbh, false);
while ($counter < $sql_result_file_length) {
    $query_strlen = strlen(trim($sql_result_file_data[$counter]));
    if ($dbvar_maxpacks < $query_strlen) {
        DUPX_Log::Info("**ERROR** Query size limit [length={$query_strlen}] [sql=" . substr($sql_result_file_data[$counter], 75) . "...]");
        $dbquery_errs++;
    } elseif ($query_strlen > 0) {
        @mysqli_free_result(@mysqli_query($dbh, $sql_result_file_data[$counter]));
        $err = mysqli_error($dbh);
        //Check to make sure the connection is alive
        if (!empty($err)) {
            if (!mysqli_ping($dbh)) {
                mysqli_close($dbh);
                $dbh = DupUtil::db_connect($_POST['dbhost'], $_POST['dbuser'], $_POST['dbpass'], $_POST['dbname'], $_POST['dbport']);
                // Reset session setup
                @mysqli_query($dbh, "SET wait_timeout = {$GLOBALS['DB_MAX_TIME']}");
                DupUtil::mysql_set_charset($dbh, $_POST['dbcharset'], $_POST['dbcollate']);
            }
            DUPX_Log::Info("**ERROR** database error write '{$err}' - [sql=" . substr($sql_result_file_data[$counter], 0, 75) . "...]");
            $dbquery_errs++;
            //Buffer data to browser to keep connection open
        } else {
            if ($fcgi_buffer_count++ > $fcgi_buffer_pool) {
                $fcgi_buffer_count = 0;
                DupUtil::fcgi_flush();
            }
            $dbquery_rows++;
コード例 #29
0
ファイル: mysqli.php プロジェクト: NavaINT1876/ccustoms
 /**
  * Determines if the connection to the server is active.
  *
  * @return  boolean  True if connected to the database engine.
  *
  * @since   11.1
  */
 public function connected()
 {
     if (is_object($this->connection)) {
         return mysqli_ping($this->connection);
     }
     return false;
 }
コード例 #30
0
 /**
  * escapes the given string via mysqlX_real_esacpe_string (if function exists & a db-connection is available) or mysqlX_escape_string
  * @param string $string
  * @return string $string
  */
 function escapeSql($string)
 {
     $connection = xtc_db_connect();
     if (function_exists('mysqli_real_escape_string') && mysqli_ping($connection)) {
         return mysqli_real_escape_string($connection, $string);
     } else {
         return mysqli_real_escape_string($connection, $string);
     }
 }