In Cake4 I had worked out how to make prepared statements to use in situations where I had to do the same query many times. This was WAY faster than defining the query for each use.
My Cake4 process was:
//Make a template query
$this->query = $this->Orders->find()
->where(['Orders.id' => 5])
->contain(['Client', 'OrderLines']);
//get a statement object
$this-statement = $this->Orders->getConnection()->prepare($query);
//Now the heavy lifting is done and the statement has the query as a string
//In that string the conditional values are identified as ':c0', ':c1', etc.
//then, in later code when I know the actual values to use:
$this->statement->bindValue(':c0', $orderId, 'integer');
$this->statement->execute(); //not sure what was happing here
//and I could get my result set
$result = (new ResultSet($this->query, $this->statement))->first();
debug($r->id);
}
I’ve fumbled my way through the creation of a Statement and the binding of the values in Cake5. I was not able to break creation and binding of the values into separate steps and I’m not thrilled about that…
I can get various array results out of the Statement object but I can’t figure out how to get a ResultSet in Cake5.
This is my Cake5 process so far:
//I make a template query, then set a property to hold the
//string version of the sql (with :c0, :c1, etc)
$this->queryString = $this->makeAQuery()->sql();
//Then I make my Statement and bind the values in a single step
$statement = $this->Order->getConnection()->execute(
$this->queryString,
[':c0' => $orderId],
[':c0' => 'integer']
);
//$statement->fetchAssoc() and other array getters work
//stuck here
//$result = new ResultSet(?????)
At a minimum I would like to know how to get a ResultSet from my prepared statement.
Ideally, I’d like to get a sketch of how a person who actually understood Cake5 at this level would solve this problem.