Database driver dongle

This class uses regex to convert MySQL to various other drivers.

Protected properties

protected DB $db

db helper object

protected string $driver

driver to convert to: mysql, sqlite, pgsql, sqlsrv, postgis

protected bool $strictModeDisabled

strictModeDisabled used to determine whether strict mode has been disabled

Public methods

public void __construct($driver='mysql', $db=NULL)


  • $driver
  • $db

public void cast($sql, $asType='INTEGER')

cast for some drivers that require same-type comparisons

  • $sql
  • $asType

public void convertTimestamps(string $table, string|array $columns=NULL)

convertTimestamps alters a table's TIMESTAMP field(s) to be nullable and converts existing values.

This is needed to transition from older Laravel code that set DEFAULT 0, which is an invalid date in newer MySQL versions where NO_ZERO_DATE is included in strict mode.

  • string $table
  • string|array $columns - Column name(s). Defaults to ['created_at', 'updated_at']

public void disableStrictMode()

disableStrictMode is used to disable strict mode during migration

public void getDriver()

getDriver returns the driver name as a string, eg: pgsql

public void getTablePrefix()

getTablePrefix gets the table prefix

public void parse($sql)

parse transforms an SQL statement to match the active driver.

  • $sql

public void parseBooleanExpression($sql)

parseBooleanExpression transforms true|false expressions in a statement

  • $sql

public void parseConcat($sql)

parseConcat transforms CONCAT statement

  • $sql

public void parseGroupConcat($sql)

parseGroupConcat transforms GROUP_CONCAT statement

  • $sql

public void parseIfNull($sql)

parseIfNull transforms IFNULL statement

  • $sql

public void raw($sql)

raw transforms and executes a raw SQL statement

  • $sql