From 91d7d1fa97a621578a61c673b3274ded24798cb6 Mon Sep 17 00:00:00 2001 From: Theodore Brown Date: Tue, 22 Oct 2024 23:38:41 -0500 Subject: [PATCH] Update to PeachySQL dev-master --- README.md | 2 +- composer.json | 5 +++-- src/Entities.php | 4 ++-- test/DbTestCase.php | 2 +- test/MssqlDbTest.php | 18 +++++++++++------- test/MysqlDbTest.php | 13 ++++++------- test/src/Config.php | 18 ++---------------- test/src/LegacyUsers.php | 2 +- 8 files changed, 27 insertions(+), 37 deletions(-) diff --git a/README.md b/README.md index 77b0f98..3afd568 100644 --- a/README.md +++ b/README.md @@ -66,7 +66,7 @@ class Users extends Entities If it is necessary to bind parameters in the base query, use `getBaseSelect` instead: ```php -use PeachySQL\QueryBuilder\SqlParams; +use DevTheorem\PeachySQL\QueryBuilder\SqlParams; // ... protected function getBaseSelect(QueryOptions $options): SqlParams { diff --git a/composer.json b/composer.json index e88bea7..28ec953 100644 --- a/composer.json +++ b/composer.json @@ -19,9 +19,10 @@ "require": { "php": ">=8.1", "ext-json": "*", - "devtheorem/peachy-sql": "^6.3.1", + "ext-pdo": "*", + "devtheorem/peachy-sql": "dev-master", "psr/http-message": "^1.1 || ^2.0", - "shrikeh/teapot": "^2.3.1" + "shrikeh/teapot": "^3.0" }, "require-dev": { "friendsofphp/php-cs-fixer": "^3.64", diff --git a/src/Entities.php b/src/Entities.php index 1574fb8..c6a48ad 100644 --- a/src/Entities.php +++ b/src/Entities.php @@ -4,8 +4,8 @@ namespace DevTheorem\Phaster; -use PeachySQL\PeachySql; -use PeachySQL\QueryBuilder\SqlParams; +use DevTheorem\PeachySQL\PeachySql; +use DevTheorem\PeachySQL\QueryBuilder\SqlParams; use Teapot\{HttpException, StatusCode}; abstract class Entities diff --git a/test/DbTestCase.php b/test/DbTestCase.php index b11e13b..4d561e6 100644 --- a/test/DbTestCase.php +++ b/test/DbTestCase.php @@ -4,8 +4,8 @@ namespace DevTheorem\Phaster\Test; +use DevTheorem\PeachySQL\PeachySql; use DevTheorem\Phaster\Test\src\{LegacyUsers, ModernUsers, Users}; -use PeachySQL\PeachySql; use PHPUnit\Framework\TestCase; abstract class DbTestCase extends TestCase diff --git a/test/MssqlDbTest.php b/test/MssqlDbTest.php index 4347acb..6b6b352 100644 --- a/test/MssqlDbTest.php +++ b/test/MssqlDbTest.php @@ -2,9 +2,9 @@ namespace DevTheorem\Phaster\Test; +use DevTheorem\PeachySQL\PeachySql; use DevTheorem\Phaster\Test\src\App; -use PeachySQL\PeachySql; -use PeachySQL\SqlServer; +use PDO; /** * @group mssql @@ -17,13 +17,17 @@ public static function dbProvider(): PeachySql { if (!self::$db) { $c = App::$config; - $conn = sqlsrv_connect($c->getSqlsrvServer(), $c->getSqlsrvConnInfo()); + $server = $c->getSqlsrvServer(); + $username = ''; + $password = ''; - if (!$conn) { - throw new \Exception('Failed to connect to SQL server: ' . print_r(sqlsrv_errors(), true)); - } + $pdo = new PDO("sqlsrv:server=$server", $username, $password, [ + PDO::ATTR_EMULATE_PREPARES => false, + PDO::SQLSRV_ATTR_FETCHES_NUMERIC_TYPE => true, + 'Database' => 'PeachySQL', + ]); - self::$db = new SqlServer($conn); + self::$db = new PeachySql($pdo); self::createTestTable(self::$db); } diff --git a/test/MysqlDbTest.php b/test/MysqlDbTest.php index 8afb4de..5c198a8 100644 --- a/test/MysqlDbTest.php +++ b/test/MysqlDbTest.php @@ -2,9 +2,9 @@ namespace DevTheorem\Phaster\Test; +use DevTheorem\PeachySQL\PeachySql; use DevTheorem\Phaster\Test\src\App; -use PeachySQL\Mysql; -use PeachySQL\PeachySql; +use PDO; /** * @group mysql @@ -17,13 +17,12 @@ public static function dbProvider(): PeachySql { if (!self::$db) { $c = App::$config; - $conn = new \mysqli($c->getMysqlHost(), $c->getMysqlUser(), $c->getMysqlPassword(), $c->getMysqlDatabase()); - if ($conn->connect_error !== null) { - throw new \Exception('Failed to connect to MySQL: ' . $conn->connect_error); - } + $pdo = new PDO($c->getMysqlDsn(), $c->getMysqlUser(), $c->getMysqlPassword(), [ + PDO::ATTR_EMULATE_PREPARES => false, + ]); - self::$db = new Mysql($conn); + self::$db = new PeachySql($pdo); self::createTestTable(self::$db); } diff --git a/test/src/Config.php b/test/src/Config.php index d9b2e80..052222f 100644 --- a/test/src/Config.php +++ b/test/src/Config.php @@ -7,9 +7,9 @@ */ class Config { - public function getMysqlHost(): string + public function getMysqlDsn(): string { - return '127.0.0.1'; + return "mysql:host=127.0.0.1;port=3306;dbname=Phaster"; } public function getMysqlUser(): string @@ -22,22 +22,8 @@ public function getMysqlPassword(): string return ''; } - public function getMysqlDatabase(): string - { - return 'Phaster'; - } - public function getSqlsrvServer(): string { return '(local)\SQLEXPRESS'; } - - public function getSqlsrvConnInfo(): array - { - return [ - 'Database' => 'Phaster', - 'ReturnDatesAsStrings' => true, - 'CharacterSet' => 'UTF-8', - ]; - } } diff --git a/test/src/LegacyUsers.php b/test/src/LegacyUsers.php index 4f1d67e..a43907c 100644 --- a/test/src/LegacyUsers.php +++ b/test/src/LegacyUsers.php @@ -4,8 +4,8 @@ namespace DevTheorem\Phaster\Test\src; +use DevTheorem\PeachySQL\QueryBuilder\SqlParams; use DevTheorem\Phaster\{Entities, QueryOptions}; -use PeachySQL\QueryBuilder\SqlParams; class LegacyUsers extends Entities {