* - flags : Optional bitfield of DBO_* constants that define connection, protocol,
* buffering, and transaction behavior. It is STRONGLY adviced to leave the DBO_DEFAULT
* flag in place UNLESS this this database simply acts as a key/value store.
- * - driver: Optional name of a specific DB client driver. For MySQL, there is the old
- * 'mysql' driver and the newer 'mysqli' driver.
+ * - driver: Optional name of a specific DB client driver. For MySQL, there is only the
+ * 'mysqli' driver; the old one 'mysql' has been removed.
* - variables: Optional map of session variables to set after connecting. This can be
* used to adjust lock timeouts or encoding modes and the like.
* - connLogger: Optional PSR-3 logger interface instance.
*/
final public static function factory( $dbType, $p = [] ) {
static $canonicalDBTypes = [
- 'mysql' => [ 'mysqli', 'mysql' ],
+ 'mysql' => [ 'mysqli' ],
'postgres' => [],
'sqlite' => [],
'oracle' => [],
];
static $classAliases = [
'DatabaseMssql' => DatabaseMssql::class,
- 'DatabaseMysql' => DatabaseMysql::class,
'DatabaseMysqli' => DatabaseMysqli::class,
'DatabaseSqlite' => DatabaseSqlite::class,
'DatabasePostgres' => DatabasePostgres::class
$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->getLBInfo( 'replica' ) === true ) {
+ throw new DBError(
+ $this,
+ '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();
$fname = __METHOD__,
callable $inputCallback = null
) {
+ $delimiterReset = new ScopedCallback(
+ function ( $delimiter ) {
+ $this->delimiter = $delimiter;
+ },
+ [ $this->delimiter ]
+ );
$cmd = '';
while ( !feof( $fp ) ) {
if ( $done || feof( $fp ) ) {
$cmd = $this->replaceVars( $cmd );
- if ( !$inputCallback || call_user_func( $inputCallback, $cmd ) ) {
+ if ( $inputCallback ) {
+ $callbackResult = call_user_func( $inputCallback, $cmd );
+
+ if ( is_string( $callbackResult ) || !$callbackResult ) {
+ $cmd = $callbackResult;
+ }
+ }
+
+ if ( $cmd ) {
$res = $this->query( $cmd, $fname );
if ( $resultCallback ) {
}
}
+ ScopedCallback::consume( $delimiterReset );
return true;
}