migliori / power-lite-pdo

PowerLite PDO is a DBAL PDO Wrapper, a lightweight and powerful PHP library that provides an efficient way to interact with multiple types of databases
https://www.powerlitepdo.com
GNU General Public License v3.0
10 stars 0 forks source link

Fatal Parse errors and TypeErrors throughout your code #2

Closed dogfella closed 2 months ago

dogfella commented 2 months ago

This package appears to somewhat work similar to the old school Idiorm / Paris package except not as many features as that package.

However, there are parse errors in your default installation. No modifications have bee done to your base code and I'm trying to run your "Db Examples - PowerLite PDO" example. to take it for a spin. But, nothing runs from the get-go. No errors except the ones coming from your code base.

Running: Localhost, with PHP 7.4.26 on Xampp

Below is the error. Are you limiting this to PHP greater than 8.0? Your documentation says otherwise and I will not be able to use any of your code base, nor will a substantial portion of the web if this is required. Many online applications will not function in 8.XX+ And, I do believe this error due to the "|" pipe is because of a requirement for 8.0+

Parse error: syntax error, unexpected '|', expecting variable (T_VARIABLE) in E:\xampp\htdocs\powerlitedb\vendor\migliori\power-lite-pdo\src\Query\QueryBuilder.php on line 50

inside here: powerlitedb/vendor/migliori/power-lite-pdo/src/Query/QueryBuilder.php

There are further similar errors on Lines 74 and 76 if line 50 is corrected without using the pipe | symbol and using either int or array.

And, also correcting all three lines of 50, 74, 76 will yield the following TypeError
I did not explore your code further after these errors.

powerlitedb/vendor/migliori/power-lite-pdo/src/Result/Result.php on line 46.

Fatal error: Uncaught TypeError: Return value of Migliori\PowerLitePdo\Result\Result::fetch() must be an instance of Migliori\PowerLitePdo\Result\mixed, instance of stdClass returned in E:\xampp\htdocs\powerlitedb\vendor\migliori\power-lite-pdo\src\Result\Result.php:46 Stack trace: #0 E:\xampp\htdocs\powerlitedb\vendor\migliori\power-lite-pdo\src\Query\QueryBuilder.php(564): Migliori\PowerLitePdo\Result\Result->fetch(5) #1 E:\xampp\htdocs\powerlitedb\vendor\migliori\power-lite-pdo\src\Db.php(518): Migliori\PowerLitePdo\Query\QueryBuilder->fetch(5) #2 E:\xampp\htdocs\powerlitedb\db-examples-test.php(55): Migliori\PowerLitePdo\Db->fetch() #3 {main} thrown in E:\xampp\htdocs\powerlitedb\vendor\migliori\power-lite-pdo\src\Result\Result.php on line 46

Coding Error messages and scree grabs from VSCode: vendor/migliori/power-lite-pdo/src/Query/QueryBuilder.php

line50

line_74-75

migliori commented 2 months ago

Hi,

I fixed the PHP 7.4 typing errors and tested with the example files, please run composer update and everything should be fine now.

dogfella commented 1 month ago

Thank you for the quick response. I looked at your update with a Diff and I saw quite a lot of updates to files. I am glad I didn't try and dive in and work through some of the issues myself due to the dependencies and file structure. I typically do not address questions with a package or script and hack through the issues and fix them.

I tried a couple of your example files after your update and they work. I will look into the script more to test a few other things out. I do have a question though:

Q1. What are your long-term goals with this project for package requirements and more specifically, will you start requiring PHP Version 8.XX in order to use this package? If so, approximately when in general? Weeks, months, or a year or two, etc... Or, will you support version 7.XX

Thanks again for your input.

migliori commented 1 month ago

Thanks for your comment. I need this package to be widely compatible on any reasonable php version, I use it with my PHP Form Builder and CRUD Generator, which are used by many people all over the world.

So it'll still be PHP 7.4+ friendly until almost no one uses it, I guess at least for about 2 years.

dogfella commented 1 week ago

So, I was revisiting your project and found further Type Errors. This time with FetchAll :

Using your examples in your documentation it fails both with fetching Objects and Associative Arrays.
https://www.powerlitepdo.com/docs/1.0.0/db-data-fetching-and-conversion/

Try this code in your example yourself. Convert to a simple array :

`$db->select('users', ['id', 'name']);

// fetch all rows from the result set and return them as associative arrays. $result = $db->fetchAll(PDO::FETCH_ASSOC);

// convert the result to an indexed array. E.g.: ["name,", "name2", ...] $result = $db->convertToSimpleArray($result, 'name');

var_dump($result); `

Is the code incorrect in your example or is there still Type Errors in your code?

However, the default Fetch Mode appears to work fine, just the FetchAll is failing:

$db->query("SELECT * FROM users"); while ($row = $db->fetch()) { echo $row->name; }

Did you say that Powerlite is used in your applications? Does it fail in those applications too? It would appear there would have been reported issues in those applications.

dogfella commented 1 week ago

A little digging shows that In Result.php

Is line 56 correct with :mixed

public function fetchAll(int $fetch_parameters = PDO::FETCH_OBJ): mixed

migliori commented 1 week ago

Hi,

Thanks for reporting this.

It's a PHP 7.4 issue, I use it with PHP 8, which works fine.

PHP 7.4 doesn't understand the :mixed in vendor\migliori\power-lite-pdo\src\Result\Result.php L.56

You just have to remove this :mixed to get rid of this error. Or update with Composer, I just released the version v1.1.1 (https://github.com/migliori/power-lite-pdo/blob/main/CHANGELOG.md)

If you need anything else you're welcome,

Gilles Gilles Migliori - Web developer https://codecanyon.net/user/migli/portfoliohttps://www.miglisoft.com+33 9 54 71 79 93 +33 6 99 07 24 43

------ Message d'origine ------ De "dogfella" @.> À "migliori/power-lite-pdo" @.> Cc "Gilles Migliori" @.>; "State change" @.> Date 26/09/2024 16:35:10 Objet Re: [migliori/power-lite-pdo] Fatal Parse errors and TypeErrors throughout your code (Issue #2)

So, I was revisiting your project and found further Type Errors. This time with FetchAll :

Fatal error: Uncaught TypeError: Return value of Migliori\PowerLitePdo\Result\Result::fetchAll() must be an instance of Migliori\PowerLitePdo\Result\mixed, array returned

Using your examples in your documentation it fails both with fetching Objects and Associative Arrays. https://www.powerlitepdo.com/docs/1.0.0/db-data-fetching-and-conversion/

Try this code in your example yourself. Convert to a simple array :

`$db->select('users', ['id', 'name']);

// fetch all rows from the result set and return them as associative arrays. $result = $db->fetchAll(PDO::FETCH_ASSOC);

// convert the result to an indexed array. E.g.: ["name,", "name2", ...] $result = $db->convertToSimpleArray($result, 'name');

var_dump($result); `

Is the code incorrect in your example or is there still Type Errors in your code?

However, the default Fetch Mode appears to work fine, just the FetchAll is failing:

$db->query("SELECT * FROM users"); while ($row = $db->fetch()) { echo $row->name; }

Did you say that Powerlite is used in your applications? Does it fail in those applications too? It would appear there would have been reported issues in those applications.

— Reply to this email directly, view it on GitHub https://github.com/migliori/power-lite-pdo/issues/2#issuecomment-2377154924, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABZVHVABDYI4LAGF2HQYJLLZYQLR5AVCNFSM6AAAAABMHIFIUSVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDGNZXGE2TIOJSGQ. You are receiving this because you modified the open/close state.Message ID: @.***>