Search moodle.org's
Developer Documentation

See Release Notes

  • Bug fixes for general core bugs in 3.11.x will end 14 Nov 2022 (12 months plus 6 months extension).
  • Bug fixes for security issues in 3.11.x will end 13 Nov 2023 (18 months plus 12 months extension).
  • PHP version: minimum PHP 7.3.0 Note: minimum PHP version has increased since Moodle 3.10. PHP 7.4.x is supported too.

Experimental pdo database class.

Copyright: 2008 Andrei Bautu
License: http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
File Size: 382 lines (14 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 1 file
 lib/dml/pdo_moodle_database.php

Defines 1 class

sqlite3_pdo_moodle_database:: (16 methods):
  driver_installed()
  get_dbfamily()
  get_dbtype()
  configure_dbconnection()
  create_database()
  get_dsn()
  get_dbfilepath()
  get_tables()
  get_indexes()
  fetch_columns()
  normalise_value()
  get_limit_clauses()
  delete_records()
  sql_concat()
  sql_concat_join()
  sql_bitxor()


Class: sqlite3_pdo_moodle_database  - X-Ref

Experimental pdo database class

driver_installed()   X-Ref
Detects if all needed PHP stuff installed.
Note: can be used before connect()

return: mixed true if ok, string if something

get_dbfamily()   X-Ref
Returns database family type - describes SQL dialect
Note: can be used before connect()

return: string db family name (mysql, postgres, mssql, oracle, etc.)

get_dbtype()   X-Ref
Returns more specific database driver type
Note: can be used before connect()

return: string db type mysqli, pgsql, oci, mssql, sqlsrv

configure_dbconnection()   X-Ref
No description

create_database($dbhost, $dbuser, $dbpass, $dbname, array $dboptions=null)   X-Ref
Attempt to create the database

param: string $dbhost
param: string $dbuser
param: string $dbpass
param: string $dbname
return: bool success

get_dsn()   X-Ref
Returns the driver-dependent DSN for PDO based on members stored by connect.
Must be called after connect (or after $dbname, $dbhost, etc. members have been set).

return: string driver-dependent DSN

get_dbfilepath()   X-Ref
Returns the file path for the database file, computed from dbname and/or dboptions.
If dboptions['file'] is set, then it is used (use :memory: for in memory database);
else if dboptions['path'] is set, then the file will be <dboptions path>/<dbname>.sq3.php;
else if dbhost is set and not localhost, then the file will be <dbhost>/<dbname>.sq3.php;
else the file will be <moodle data path>/<dbname>.sq3.php

return: string file path to the SQLite database;

get_tables($usecache=true)   X-Ref
Return tables in database WITHOUT current prefix.

param: bool $usecache if true, returns list of cached tables.
return: array of table names in lowercase and without prefix

get_indexes($table)   X-Ref
Return table indexes - everything lowercased

param: string $table The table we want to get indexes from.
return: array of arrays

fetch_columns(string $table)   X-Ref
Returns detailed information about columns in table.

param: string $table name
return: array array of database_column_info objects indexed with column names

normalise_value($column, $value)   X-Ref
Normalise values based in RDBMS dependencies (booleans, LOBs...)

param: database_column_info $column column metadata corresponding with the value we are going to normalise
param: mixed $value value we are going to normalise
return: mixed the normalised value

get_limit_clauses($sql, $limitfrom=0, $limitnum=0)   X-Ref
Returns the sql statement with clauses to append used to limit a recordset range.

param: string $sql the SQL statement to limit.
param: int $limitfrom return a subset of records, starting at this point (optional, required if $limitnum is set).
param: int $limitnum return a subset comprising this many records (optional, required if $limitfrom is set).
return: string the SQL statement with limiting clauses

delete_records($table, array $conditions=null)   X-Ref
Delete the records from a table where all the given conditions met.
If conditions not specified, table is truncated.

param: string $table the table to delete from.
param: array $conditions optional array $fieldname=>requestedvalue with AND in between
return: returns success.

sql_concat()   X-Ref
Returns the proper SQL to do CONCAT between the elements passed
Can take many parameters

param: string $element
return: string

sql_concat_join($separator="' '", $elements=array()   X-Ref
Returns the proper SQL to do CONCAT between the elements passed
with a given separator

param: string $separator
param: array  $elements
return: string

sql_bitxor($int1, $int2)   X-Ref
Returns the SQL text to be used in order to perform one bitwise XOR operation
between 2 integers.

param: integer int1 first integer in the operation
param: integer int2 second integer in the operation
return: string the piece of SQL code to be used in your statement.