Skip to content
This repository has been archived by the owner on Dec 21, 2021. It is now read-only.

Commit

Permalink
Introduce a new database API, based on PDO
Browse files Browse the repository at this point in the history
This commit brings a new API for the datbase layer.
Instead of creating our dynamic SQL queries with concat and sprintf

The way it works is that you first start with on of the factory methods
available in the Database class. You then use the created
DatabaseStatement and its chainable API to add `part` to the clause.

This is very much a WIP. The API will change at some point.

Re symphonycms#2604
Fixes symphonycms#2562
Re symphonycms#2472
Re symphonycms#2448
Fixes #2425
Re symphonycms#2015

Picked from 69439c6
Picked from 33102ad
  • Loading branch information
nitriques committed Apr 20, 2018
1 parent 8fa9c21 commit a939719
Show file tree
Hide file tree
Showing 18 changed files with 2,678 additions and 31 deletions.
2 changes: 1 addition & 1 deletion symphony/lib/core/class.errorhandler.php
Expand Up @@ -261,7 +261,7 @@ public static function render($e)
$queries = null;

if (is_object(Symphony::Database())) {
$debug = Symphony::Database()->debug();
$debug = Symphony::Database()->getLogs();

if (!empty($debug)) {
foreach ($debug as $query) {
Expand Down
34 changes: 4 additions & 30 deletions symphony/lib/core/class.symphony.php
Expand Up @@ -317,6 +317,7 @@ public static function ExtensionManager()
* is omitted, this function will set `$Database` to be of the `MySQL`
* class.
*
* @deprecated @since Symphony 3.0.0 - This function now does nothing
* @since Symphony 2.3
* @param StdClass $database (optional)
* The class to handle all Database operations, if omitted this function
Expand All @@ -326,12 +327,6 @@ public static function ExtensionManager()
*/
public static function setDatabase(StdClass $database = null)
{
if (self::Database()) {
return true;
}

self::$Database = !is_null($database) ? $database : new MySQL;

return true;
}

Expand All @@ -357,38 +352,17 @@ public static function Database()
*/
public static function initialiseDatabase()
{
self::setDatabase();
$details = self::Configuration()->get('database');
self::$Database = new Database($details);

try {
if (!self::Database()->connect($details['host'], $details['user'], $details['password'], $details['port'], $details['db'])) {
return false;
}
self::Database()->connect();

if (!self::Database()->isConnected()) {
return false;
}

self::Database()->setPrefix($details['tbl_prefix']);
self::Database()->setCharacterEncoding();
self::Database()->setCharacterSet();
self::Database()->setTimeZone(self::Configuration()->get('timezone', 'region'));

if (isset($details['query_caching'])) {
if ($details['query_caching'] == 'off') {
self::Database()->disableCaching();
} elseif ($details['query_caching'] == 'on') {
self::Database()->enableCaching();
}
}

if (isset($details['query_logging'])) {
if ($details['query_logging'] == 'off') {
self::Database()->disableLogging();
} elseif ($details['query_logging'] == 'on') {
self::Database()->enableLogging();
}
}
} catch (DatabaseException $e) {
self::throwCustomError(
$e->getDatabaseErrorCode() . ': ' . $e->getDatabaseErrorMessage(),
Expand Down Expand Up @@ -959,7 +933,7 @@ public static function render($e)
}

if (is_object(Symphony::Database())) {
$debug = Symphony::Database()->debug();
$debug = Symphony::Database()->getLogs();

if (!empty($debug)) {
foreach ($debug as $query) {
Expand Down

0 comments on commit a939719

Please sign in to comment.