/** @var TransactionProfiler */
protected $trxProfiler;
- /**
- * @var bool Whether writing is allowed on this connection.
- * Should be false for connections to replicas.
- */
- protected $allowWrite = true;
-
/**
* Constructor and database handle and attempt to connect to the DB server
*
$this->connLogger = $params['connLogger'];
$this->queryLogger = $params['queryLogger'];
$this->errorLogger = $params['errorLogger'];
- $this->allowWrite = empty( $params['noWrite'] );
// Set initial dummy domain until open() sets the final DB/prefix
$this->currentDomain = DatabaseDomain::newUnspecified();
$p['variables'] = isset( $p['variables'] ) ? $p['variables'] : [];
$p['tablePrefix'] = isset( $p['tablePrefix'] ) ? $p['tablePrefix'] : '';
$p['schema'] = isset( $p['schema'] ) ? $p['schema'] : '';
- $p['cliMode'] = isset( $p['cliMode'] ) ? $p['cliMode'] : ( PHP_SAPI === 'cli' );
+ $p['cliMode'] = isset( $p['cliMode'] )
+ ? $p['cliMode']
+ : ( PHP_SAPI === 'cli' || PHP_SAPI === 'phpdbg' );
$p['agent'] = isset( $p['agent'] ) ? $p['agent'] : '';
if ( !isset( $p['connLogger'] ) ) {
$p['connLogger'] = new \Psr\Log\NullLogger();
}
if ( $isWrite ) {
- if ( !$this->allowWrite ) {
+ if ( $this->getLBInfo( 'replica' ) === true ) {
throw new DBError(
$this,
- 'Write operations are not allowed on this database connection!'
+ 'Write operations are not allowed on replica database connections.'
);
}
-
# In theory, non-persistent writes are allowed in read-only mode, but due to things
# like https://bugs.mysql.com/bug.php?id=33669 that might not work anyway...
$reason = $this->getReadOnlyReason();