mysql - PHP Inserting DB values into values in a class -


i want pull values db , insert them variables in class.

is best , ideal way create db class , reference class within main class set protected values values db?

    if(!empty($s)){         $_client_id=$s['api_id'];         $_client_secret=$s['api_password'];         $_client_id=$s['api_secret'];         $_access_token=$s['api_token'];         $_username=$s['api_user'];     }  class myclass {     protected $_client_id = '20123123';     protected $_client_secret = '76fesresg45grgerg3g34';     protected $_username = 'letshe' 

the best way use pdo's ability manipulate objects.

get rid of mysqli, , use pdo objects right out of sql:

class myclass {     protected $client_id;     protected $client_secret;     protected $username }  $sql = "select * my_class id=1"; $myclassinstance = $pdo->query($sql)->fetchobject('myclass');  $sql = "select * my_class"; $myclasscollection = $pdo->query($sql)->fetchall(pdo::fetch_class, 'myclass'); 

note unlike mysqli, pdo can let provide constructor parameters, call setters, assign properties either before or after constructor call.


Comments

Popular posts from this blog

serialization - Convert Any type in scala to Array[Byte] and back -

matplotlib support failed in PyCharm on OSX -

python - Matplotlib: TypeError: 'AxesSubplot' object is not callable -