October\Rain\Database\Dongle

Source: ~/vendor/october/rain/src/Database/Dongle.php

Database driver dongle

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

Protected properties

protected DB $db

Database helper object

protected string $driver

Driver to convert to: mysql, sqlite, pgsql, sqlsrv, postgis.

protected bool $strictModeDisabled

Used to determine whether strict mode has been disabled.

Public methods

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

Constructor.

Parameters
  • $driver
  • $db

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

Some drivers require same-type comparisons.

Parameters
  • string $sql
  • $asType

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

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.

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

public void disableStrictMode()

Used to disable strict mode during migrations

public string getDriver()

Returns the driver name as a string, eg: pgsql

public string getTablePrefix()

Get the table prefix.

public string parse(string $sql)

Transforms an SQL statement to match the active driver.

Parameters
  • string $sql

public string parseBooleanExpression(string $sql)

Transforms true|false expressions in a statement.

Parameters
  • string $sql

public string parseConcat(string $sql)

Transforms CONCAT statement.

Parameters
  • string $sql

public string parseGroupConcat(string $sql)

Transforms GROUP_CONCAT statement.

Parameters
  • string $sql

public string parseIfNull(string $sql)

Transforms IFNULL statement.

Parameters
  • string $sql

public mixed raw(string $sql)

Transforms and executes a raw SQL statement

Parameters
  • string $sql