1
0
mirror of https://github.com/e107inc/e107.git synced 2025-03-14 17:39:46 +01:00

Don't spam database server with connections

- MOD: Silently ignore failures to e_db_mysql::close(); if it's failing, it's probably already closed
- FIX: Close the PDO or mysqli connection after each e_db_abstractTest test
- MOD: Changed class2.php's $sql variable to be hinted as an e_db instead of e_db_mysql
This commit is contained in:
Nick Liu 2020-01-19 14:33:11 +01:00
parent 1fd0a171a0
commit 8b354adf44
No known key found for this signature in database
GPG Key ID: 1167C5F9C9897637
6 changed files with 22 additions and 16 deletions

View File

@ -2,7 +2,7 @@
/*
* e107 website system
*
* Copyright (C) 2008-2010 e107 Inc (e107.org)
* Copyright (C) 2008-2020 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
@ -391,7 +391,7 @@ e107::getSingleton('e107_traffic'); // We start traffic counting ASAP
// e107_require_once(e_HANDLER.'mysql_class.php');
//DEPRECATED, BC, $e107->sql caught by __get()
/** @var e_db_mysql $sql */
/** @var e_db $sql */
$sql = e107::getDb(); //TODO - find & replace $sql, $e107->sql
$sql->db_SetErrorReporting(false);

View File

@ -1,8 +1,12 @@
<?php
/**
* Created by PhpStorm.
* Date: 2/8/2019
* Time: 11:46 AM
* e107 website system
*
* Copyright (C) 2008-2020 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
* PDO MySQL Handler
*/
// Legacy Fix.

View File

@ -1290,8 +1290,7 @@ class e_db_mysql implements e_db
{
$this->provide_mySQLaccess();
e107::getSingleton('e107_traffic')->BumpWho('db Close', 1);
$result = mysqli_close($this->mySQLaccess);
if ($result === false) $this->dbError('dbClose');
@mysqli_close($this->mySQLaccess);
}

View File

@ -2,7 +2,7 @@
/**
* e107 website system
*
* Copyright (C) 2008-2019 e107 Inc (e107.org)
* Copyright (C) 2008-2020 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*
@ -20,6 +20,14 @@ abstract class e_db_abstractTest extends \Codeception\Test\Unit
*/
abstract protected function makeDb();
/**
* Prevent creating too many connections to database server
*/
public function _after()
{
$this->db->close();
}
protected function loadConfig()
{
/** @var Helper\DelayedDb $db */
@ -47,9 +55,6 @@ abstract class e_db_abstractTest extends \Codeception\Test\Unit
$this->assertTrue($result);
}
public function testGetMode()
{
$actual = $this->db->getMode();
@ -1006,7 +1011,6 @@ abstract class e_db_abstractTest extends \Codeception\Test\Unit
*/
public function testSecondaryDatabaseInstance()
{
try
{
$xql = $this->makeDb();
@ -1128,8 +1132,7 @@ abstract class e_db_abstractTest extends \Codeception\Test\Unit
$empty = $xql->isEmpty($table);
$this->assertTrue($empty,"isEmpty() or truncate() failed");
$xql->close();
}
}

View File

@ -2,7 +2,7 @@
/**
* e107 website system
*
* Copyright (C) 2008-2018 e107 Inc (e107.org)
* Copyright (C) 2008-2020 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*

View File

@ -2,7 +2,7 @@
/**
* e107 website system
*
* Copyright (C) 2008-2018 e107 Inc (e107.org)
* Copyright (C) 2008-2020 e107 Inc (e107.org)
* Released under the terms and conditions of the
* GNU General Public License (http://www.gnu.org/licenses/gpl.txt)
*