Dongle driver for database that 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 __construct()

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

public cast()

public cast($sql, $asType = 'INTEGER'): string 

cast for some drivers that require same-type comparisons

public convertTimestamps()

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

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.

public disableStrictMode()

public disableStrictMode(): void

disableStrictMode is used to disable strict mode during migration

public getDriver()

public getDriver(): void

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

public getTablePrefix()

public getTablePrefix(): string 

getTablePrefix gets the table prefix

public parse()

public parse($sql, $params = null): string 

parse transforms an SQL statement to match the active driver. If params are supplied, replaces :column_name with array value without requiring a list of names. Example: custom_country_id = :country_id → custom_country_id = 7

public parseBooleanExpression()

public parseBooleanExpression($sql): string 

parseBooleanExpression transforms true|false expressions in a statement

public parseConcat()

public parseConcat($sql): string 

parseConcat transforms CONCAT statement

public parseGroupConcat()

public parseGroupConcat($sql): string 

parseGroupConcat transforms GROUP_CONCAT statement

public parseIfNull()

public parseIfNull($sql): string 

parseIfNull transforms IFNULL statement

public parseParams()

public parseParams($sql, $params): void

public parseValues()

public parseValues($sql, $data, $paramNames): void

parseValues will protect parameter values by quoting them or handling safe values. Eg:

username = :value   → username = 'foobar'
username = :value%  → username = 'foobar%'
username = %:value  → username = '%foobar'
username = %:value% → username = '%foobar%'

public raw()

public raw($sql, $params = null): void

raw transforms and executes a raw SQL statement

public rawValue()

public rawValue($sql): string 

rawValue converts a raw expression to a string