You are here

public function ConnectionTest::testMultipleStatementsForNewPhp in Zircon Profile 8.0

Same name and namespace in other branches
  1. 8 core/modules/system/src/Tests/Database/ConnectionTest.php \Drupal\system\Tests\Database\ConnectionTest::testMultipleStatementsForNewPhp()

Ensure that you cannot execute multiple statements on phpversion() > 5.5.21 or > 5.6.5.

File

core/modules/system/src/Tests/Database/ConnectionTest.php, line 125
Contains \Drupal\system\Tests\Database\ConnectionTest.

Class

ConnectionTest
Tests of the core database system.

Namespace

Drupal\system\Tests\Database

Code

public function testMultipleStatementsForNewPhp() {

  // This just tests mysql, as other PDO integrations don't allow disabling
  // multiple statements.
  if (Database::getConnection()
    ->databaseType() !== 'mysql' || !defined('\\PDO::MYSQL_ATTR_MULTI_STATEMENTS')) {
    return;
  }
  $db = Database::getConnection('default', 'default');

  // Disable the protection at the PHP level.
  try {
    $db
      ->query('SELECT * FROM {test}; SELECT * FROM {test_people}', [], [
      'allow_delimiter_in_query' => TRUE,
    ]);
    $this
      ->fail('No PDO exception thrown for multiple statements.');
  } catch (DatabaseExceptionWrapper $e) {
    $this
      ->pass('PDO exception thrown for multiple statements.');
  }
}