D
D
DVP882020-05-10 23:47:34
PHP
DVP88, 2020-05-10 23:47:34

Sequence of methods when using the chaining method?

Greetings, I ask for help in understanding the chaining method`a. It is important for me to understand how to implement a convenient query sequence, for example:
Developing a class to work with a database. At the output, we want to be able to use something like this format:

$db->table('tableName')->select(...........)->where(........)->fetch('assoc');

In place of select , respectively, there can be update , insert , delete
But here the problem is that WHERE and FETCH are part of the SELECT query, so I cannot execute it during the call to the select method with a class object, I need to do this later, but HOW?
I'm considering writing the entire query to a global class variable (eg $query), but how do I execute this entire query in total? It would be possible to create a run() method that would execute $query
$db->table('tableName')->select(...........)->where(........)->fetch('assoc')->run();

However, this is complete absurdity and I believe that there is a more correct way out, for which I have not yet had the mind

Answer the question

In order to leave comments, you need to log in

1 answer(s)
R
Rsa97, 2020-05-11
@Rsa97

As the simplest option - select only prepares the query string, where, groupBy, etc. add their substrings to it, and already fetch makes a real query to the database and returns the result.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question