php - How do I use PDO's FETCH_CLASS to assign constructor arguments? -
I want to make examples of objects using PDO. I know that there is a lot already, but only I have been found that it is possible to send an array of parameters to the constructor. I think the producer can only accept an array in the form of logic. However this will make the constructor less meaningful.
I want to create a class with my own gates and the setters:
class MyClass {Personal property is a private property B public __constructor ($ ArgA, $ argB) {$ This- & gt; Setproperty A ($ argA); $ This- & gt; SetPropertyB ($ ARGB); } Public Setproperties ($ AGR) {$ this- & gt; Property A = $ AG; }} Is there a great way to use data from a database to create an example of such a class, preferably using PDOs?
freebillin 'here:
$ handle = new pdo (" Blablalblah "); $ Statement = $ handle-> Prepare ("selection bluetooth"); $ Statement & gt; Executed (); $ Object_params = $ statement- & gt; Get (PDO :: FETCH_ASSOC); $ Object = new object ($ object_param); // or ... $ object = new object ($ object_up [["chole_1"], $ object_param ["como_2"], "etc.");
Alternatively:
class MyClass {Personal property is a private property B public __constructor () {$ handle = new PDO ("blahblahblah"); $ Statement = $ handle-> Prepare ("selection bluetooth"); $ Statement & gt; Executed (); $ Object_params = $ statement- & gt; Get (PDO :: FETCH_ASSOC); $ This- & gt; SetPropertyA ($ object_params [$ argA_key]); $ This- & gt; SetPropertyB ($ object_params [$ argB_key]); } Public Setproperties ($ AGR) {$ this- & gt; Property A = $ AG; }}
I do not know exactly what you are looking for. Can you comment?
Comments
Post a Comment