From 34e4d86e46ca6a3587af35ad52ea04ec0dba62b7 Mon Sep 17 00:00:00 2001 From: Sleon4 Date: Mon, 10 Nov 2025 17:29:35 -0500 Subject: [PATCH] fix: The connection initialization in the implementation (RunInterface) has been corrected --- src/LionDatabase/Drivers/MySQL.php | 12 +++++------- src/LionDatabase/Drivers/Schema/MySQL.php | 12 ++++++++++-- src/LionDatabase/Traits/RunInterfaceTrait.php | 4 +--- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/src/LionDatabase/Drivers/MySQL.php b/src/LionDatabase/Drivers/MySQL.php index d4e65f1..9ee5d27 100644 --- a/src/LionDatabase/Drivers/MySQL.php +++ b/src/LionDatabase/Drivers/MySQL.php @@ -63,19 +63,17 @@ /** * Provides an interface to build SQL queries dynamically in PHP applications - * that interact with MySQL databases + * that interact with MySQL databases. * * Key Features: * - * * Intuitive methods: Simple methods to build SQL queries programmatically + * * Intuitive methods: Simple methods to build SQL queries programmatically. * * SQL Injection Prevention: Helps prevent SQL injection attacks by sanitizing - * data entered in queries + * data entered in queries. * * Flexibility: Allows the construction of dynamic queries adapted to - * different application scenarios + * different application scenarios. * * Optimization for MySQL: Designed specifically to work with MySQL, - * guaranteeing compatibility and optimization with this DBMS - * - * @package Lion\Database\Drivers + * guaranteeing compatibility and optimization with this DBMS. */ class MySQL extends Connection implements AndInterface, diff --git a/src/LionDatabase/Drivers/Schema/MySQL.php b/src/LionDatabase/Drivers/Schema/MySQL.php index 40a5d5f..4a7422d 100644 --- a/src/LionDatabase/Drivers/Schema/MySQL.php +++ b/src/LionDatabase/Drivers/Schema/MySQL.php @@ -54,9 +54,9 @@ class MySQL extends Connection implements DatabaseConfigInterface, ExecuteInterf /** * {@inheritdoc} */ - public static function execute(): stdClass + public static function execute(): int|stdClass { - return parent::process(function (): stdClass { + return parent::process(function (): int|stdClass { self::prepare(self::$sql); if (!self::$stmt->execute()) { @@ -261,10 +261,14 @@ public static function createStoredProcedure(string $storedProcedure, Closure $p self::getKey(Driver::MYSQL, 'begin'), ]); + /** @var string $activeConnection */ + $activeConnection = self::$activeConnection; + $begin( DriverMySQL::run(self::$connections) ->isSchema() ->enableInsert(true) + ->connection($activeConnection) ); self::addQueryList([ @@ -319,10 +323,14 @@ public static function createView(string $view, Closure $viewBody): self self::getKey(Driver::MYSQL, 'as') ]); + /** @var string $activeConnection */ + $activeConnection = self::$activeConnection; + $viewBody( DriverMySQL::run(self::$connections) ->isSchema() ->enableInsert(true) + ->connection($activeConnection) ); return new self(); diff --git a/src/LionDatabase/Traits/RunInterfaceTrait.php b/src/LionDatabase/Traits/RunInterfaceTrait.php index a7cb379..c52f17f 100644 --- a/src/LionDatabase/Traits/RunInterfaceTrait.php +++ b/src/LionDatabase/Traits/RunInterfaceTrait.php @@ -27,9 +27,7 @@ public static function run(array $connections): self self::$connections = $connections; - self::$activeConnection = empty(self::$activeConnection) - ? self::$connections[Connection::CONNECTION_DEFAULT] - : self::$activeConnection; + self::$activeConnection = self::$connections[Connection::CONNECTION_DEFAULT]; $connectionsList = self::$connections[Connection::CONNECTION_CONNECTIONS];