Mysql
 sql >> Baza danych >  >> RDS >> Mysql

Ponowne łączenie na serwerze MySQL przestało istnieć

prawdopodobnie będziesz musiał stworzyć własną klasę, taką jak ta

  1. usuń try/except z __construct
  2. następnie połącz się z bazą danych w następujący sposób:
$conn = null;
$limit = 10;
$counter = 0;
while (true) {
  try {
    $conn = DBConn();
    break;
  }
  catch (Exception $e) {
    $conn = null;
    $counter++;
    if ($counter == $limit)
      throw $e;
  }

}

EDYTUJ 1 :

ale jeśli powiesz, że twój serwer zniknie... to może być coś takiego

protected function _connect( $persistent = false ) {
$conn = null;
$limit = 10;
$counter = 0;
while (true) {
  try {
        $this->conn = new PDO( "mysql:host=localhost;dbname=test", 'test', "hoollaahaoo" );
        $this->conn->exec( "SET CHARACTER SET utf8" );
        $this->conn->setAttribute( PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC ); 
        if ( $persistent )
            $this->conn->setAttribute( PDO::ATTR_PERSISTENT, true );
}
  catch (Exception $e) {
    $conn = null;
    $counter++;
    if ($counter == $limit)
      throw $e;
  }
}

public function __construct( $persistent = false )
{
    $this->_connect($persistent);
}



  1. Database
  2.   
  3. Mysql
  4.   
  5. Oracle
  6.   
  7. Sqlserver
  8.   
  9. PostgreSQL
  10.   
  11. Access
  12.   
  13. SQLite
  14.   
  15. MariaDB
  1. Python+MySQL — wstawianie zbiorcze

  2. Jak uzyskać surowe, skompilowane zapytanie SQL z wyrażenia SQLAlchemy?

  3. JDBC zawsze testuje ostatni wiersz tabeli MySQL?

  4. jak uzyskać szczegóły z wielu tabel?

  5. Czy w SQL można odwoływać się do siebie w dwóch tabelach?