Galette API documentation
Gestionnaire d’Adhérents en Ligne Extrêmement Tarabiscoté mais Tellement Efficace
1.0.0
Galette\Core\Db Class Reference

Public Member Functions

 __construct (array $dsn=null)
 
 __sleep ()
 
 __wakeup ()
 
 getDbVersion (bool $check_table=false)
 
 checkDbVersion ()
 
 selectAll (string $table)
 
 dropTestTable ()
 
 grantCheck (string $mode='i')
 
 getTables (string $prefix=null)
 
 getColumns (string $table)
 
 convertToUTF (string $prefix=null, bool $content_only=false)
 
 isPostgres ()
 
 select (string $table, string $alias=null)
 
 insert (string $table)
 
 update (string $table)
 
 delete (string $table)
 
 execute (SqlInterface $sql)
 
 __get (string $name)
 
 __isset (string $name)
 
 getInfos ()
 
 handleSequence (string $table, int $expected)
 
 isDuplicateException (SqlInterface $sql, Throwable $exception)
 
 isForeignKeyException (Throwable $exception)
 
 drop (string $table, bool $maymiss=false)
 
 getLastGeneratedValue (object $entity)
 
 getWarnings ()
 
 isEngineSUpported ()
 
 getUnsupportedMessage ()
 

Static Public Member Functions

static testConnectivity (string $type, string $user=null, string $pass=null, string $host=null, string $port=null, string $db=null)
 

Public Attributes

const MYSQL = 'mysql'
 
const PGSQL = 'pgsql'
 
const MYSQL_DEFAULT_PORT = 3306
 
const PGSQL_DEFAULT_PORT = 5432
 

Protected Member Functions

 log (string $query)
 

Constructor & Destructor Documentation

◆ __construct()

Galette\Core\Db::__construct ( array  $dsn = null)

Main constructor

Parameters
?array<string,string>$dsn Connection information If not set, database constants will be used.
Exceptions
Throwable

Member Function Documentation

◆ __get()

Galette\Core\Db::__get ( string  $name)

Global getter method

Parameters
string$namename of the variable we want to retrieve
Returns
mixed
Exceptions
RuntimeException

◆ __isset()

Galette\Core\Db::__isset ( string  $name)

Global isset method Required for twig to access properties via __get

Parameters
string$namename of the variable we want to retrieve
Returns
bool

◆ __sleep()

Galette\Core\Db::__sleep ( )

To store Db in session

Returns
array

◆ __wakeup()

Galette\Core\Db::__wakeup ( )

Connect again to the database on wakeup

Returns
void

◆ checkDbVersion()

Galette\Core\Db::checkDbVersion ( )

Check if database version suits our needs

Returns
boolean

◆ convertToUTF()

Galette\Core\Db::convertToUTF ( string  $prefix = null,
bool  $content_only = false 
)

Converts recursively database to UTF-8

Parameters
?string$prefix Specified table prefix
boolean$content_onlyProceed only content (no table conversion)
Returns
void

◆ delete()

Galette\Core\Db::delete ( string  $table)

Instanciate a delete query

Parameters
string$tableTable name, without prefix
Returns
Delete

◆ drop()

Galette\Core\Db::drop ( string  $table,
bool  $maymiss = false 
)

Drops a table

Parameters
string$tableTable name, without prefix
boolean$maymissWhether the table can be missing, defaults to false
Returns
void

◆ dropTestTable()

Galette\Core\Db::dropTestTable ( )

Drop test table if it exists, so we can make all checks.

Returns
void

◆ execute()

Galette\Core\Db::execute ( SqlInterface  $sql)

Execute query string

Parameters
SqlInterface$sqlSQL object
Returns
ResultSet|Result
Exceptions
Throwable

◆ getColumns()

Galette\Core\Db::getColumns ( string  $table)

Get columns for a specified table

Parameters
string$tableTable name
Returns
array<int, ColumnObject>

◆ getDbVersion()

Galette\Core\Db::getDbVersion ( bool  $check_table = false)

Retrieve current database version

Parameters
boolean$check_tableCheck if table exists, defaults to false
Returns
string
Exceptions
LogicException

◆ getInfos()

Galette\Core\Db::getInfos ( )

Get database information

Returns
array<string, string>

◆ getLastGeneratedValue()

Galette\Core\Db::getLastGeneratedValue ( object  $entity)

Get last generated value

Parameters
object$entityEntity instance
Returns
integer

@phpstan-ignore-next-line

◆ getTables()

Galette\Core\Db::getTables ( string  $prefix = null)

Get a list of Galette's tables

Parameters
?string$prefix Specified table prefix, PREFIX_DB if null
Returns
array<int, string>

◆ getUnsupportedMessage()

Galette\Core\Db::getUnsupportedMessage ( )

Get not supported database version message

Returns
string

◆ getWarnings()

Galette\Core\Db::getWarnings ( )

Get MySQL warnings

Returns
array<array<string, string>>

◆ grantCheck()

Galette\Core\Db::grantCheck ( string  $mode = 'i')

Checks GRANT access for install time

Parameters
string$modeare we at install time (i) or update time (u) ?
Returns
array<string, bool|Throwable> containing each test. Each array entry could be either true or contains an exception or false if test did not run.

◆ handleSequence()

Galette\Core\Db::handleSequence ( string  $table,
int  $expected 
)

Handle sequence on PostgreSQL

When inserting a value on a field with a sequence, this one is not incremented. This happens when installing system values (for status, titles, ...)

See also
https://bugs.galette.eu/issues/1158
https://bugs.galette.eu/issues/1374
Parameters
string$tableTable name
integer$expectedExpected value
Returns
void

◆ insert()

Galette\Core\Db::insert ( string  $table)

Instanciate an insert query

Parameters
string$tableTable name, without prefix
Returns
Insert

◆ isDuplicateException()

Galette\Core\Db::isDuplicateException ( SqlInterface  $sql,
Throwable  $exception 
)

Check if current exception is on a duplicate key

Parameters
SqlInterface$sqlSQL object
Throwable$exceptionException to check
Returns
boolean

◆ isEngineSUpported()

Galette\Core\Db::isEngineSUpported ( )

Is current database engine supported?

Returns
bool

◆ isForeignKeyException()

Galette\Core\Db::isForeignKeyException ( Throwable  $exception)

Check if current exception is related to a remaining foreign key

Parameters
Throwable$exceptionException to check
Returns
boolean

◆ isPostgres()

Galette\Core\Db::isPostgres ( )

Is current database using Postgresql?

Returns
boolean

◆ log()

Galette\Core\Db::log ( string  $query)
protected

Log queries in specific file

Parameters
string$queryQuery to add in logs
Returns
void

◆ select()

Galette\Core\Db::select ( string  $table,
string  $alias = null 
)

Instanciate a select query

Parameters
string$tableTable name, without prefix
?string$alias Tables alias, optional
Returns
Select

◆ selectAll()

Galette\Core\Db::selectAll ( string  $table)

Peform a select query on the whole table

Parameters
string$tableTable name
Returns
ResultSet

◆ testConnectivity()

static Galette\Core\Db::testConnectivity ( string  $type,
string  $user = null,
string  $pass = null,
string  $host = null,
string  $port = null,
string  $db = null 
)
static

Test if database can be contacted. Mostly used for installation

Parameters
string$typedb type
?string$user database's user
?string$pass password for the user
?string$host which host we want to connect to
?string$port which tcp port we want to connect to
?string$db database name
Returns
boolean
Exceptions
Exception|Throwable

◆ update()

Galette\Core\Db::update ( string  $table)

Instanciate an update query

Parameters
string$tableTable name, without prefix
Returns
Update

The documentation for this class was generated from the following file: