Reputation: 1302
How is the readonly $queryString
property being set inside PDOStatement class by the PDO::prepare()
execution?
Given the class definition, I don't see any functions which would set that query. Does that mean PDOStatement class can't be used if it's not generated by the PDO class instance through PDO::prepare()
function?
Upvotes: 0
Views: 125
Reputation: 157895
PDOstatement is created internally, by means of C code. And of course C code can set any properties directly.
And yes, you cannot use PDOStatement class (for anything useful) if it's not generated by the PDO class instance through PDO::prepare()
(or query()
).
However, you can redeclare and tell PDO to use it instead of standard one using code like this
$pdo->setAttribute(PDO::ATTR_STATEMENT_CLASS, ['myPDOStatement', [$pdo]]);
Upvotes: 1
Reputation: 14987
From the manual:
Introduction
[The PDOStatement class] Represents a prepared statement and, after the statement is executed, an associated result set.
This looks like it has to be created by PDO::prepare()
.
But is this a problem? I cannot say that I came across a situation where I want to create an PDOStatement object by hand.
Upvotes: 0