New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Discussion: Design of database functions #862
Comments
Usefulness of functions that just return a field from object passed as parameterThats a fair concern. public function queryWithFullResult(string $query, array $parameterValues = []): array
public function queryWithOnlyFirstRow(string $query, array $parameterValues = []): array|null I assume those will be used more often than the raw functions. The challenge right now: To get the inserted ID, we use And how do we return an error? And how do we know what went wrong? Any thoughts? Parameter-array for query-functionsThe use of I personally see getting rid of Possible SolutionI am not sure if I understand your suggestion here. |
Hmm, I noticed a few...misunderstandings in how the class is supposed to be used. |
An alternative approach would be to offer methods for the particular |
Expected Behavior
While refactoring a file for the new DB class I noticed some points that I wanted to put up for discussion.
As adoption is currently in an early stage, this is the right point to see if some points should be changed
Current Behavior
Usefulness of functions that just return a field from object passed as parameter
The old db class has functions to return data and properties from the last query result.
This was stored internally in the class.
E.g. to fetch a result array from a query done:
I agree that the result(data) should not be stored in the database object buuut:
Now we still expose functions that provide the same functionality, although the functionality is not related to the database class / object at all.
e.g.
I personally see the following issues with that:
This provides a half solution and should either do none or all of the functionality previously provided for result processing
But these are operations provided by and run completely within the scope of the
mysqliStatement
andmysqliResult
classes respectively.getStatementResult
consists ofreturn $statement->get_result();
. This provides no benefit.Parameter-array for query-functions
This is a subtle one that makes a fair amount of difference in effort for refactoring:
While query functions in the the old db class use a variable list of arguments (uses
func_get_args
) the new functions expect all values as array. Means as part of the refactoring[]
has to be added to every single query string instead of "just" replacing class & function name and occurrences of%int%
,%string%
I do see that this may have advantages (such as having no mapping internally for statement execution), but want to put it up to discussion anyways due to the disadvantage being noticed.
Possible Solution
Object functions
All or nothing. I would personally remove them and document how to use the native mysqli functions
Or: Implement prior functions also to provide same feature set
The text was updated successfully, but these errors were encountered: