rubing Posted April 11, 2008 Share Posted April 11, 2008 I am writing a user manager class. I want to have multiple levels of users and so am declaring a variable $user_level. Can I refer to $user_level in sql queries as follows? class UserManager { $user_level public function createAccount ( $in_email, $in_pw, $in_year, $in_month, $in_day, ) { // bunch of validation and other code.... //QUERY TO INSERT USER $qstr = <<<QUERY INSERT INTO Users (userlvl,password,full_name,user_email,birthdate) VALUES ('$this->user_level', '$pw','$email', '$in_year-$in_month-$in_day') QUERY; Link to comment https://forums.phpfreaks.com/topic/100660-referencing-class-variables-in-queries/ Share on other sites More sharing options...
colombian Posted April 11, 2008 Share Posted April 11, 2008 Like all other variables, if you are using it outside of the local scope of the class/function, you can it by calling the global value. global $user_level It's not clear from your code where it falls. If it is within it, you still can reference the object. If it's afterwards: $class = "UserManager"; $object = new $class; echo "{$object->user_level}\n"; //you can call it like that. And if you are using throughout, you may want to specify if the variable will be public or private - probably private. Link to comment https://forums.phpfreaks.com/topic/100660-referencing-class-variables-in-queries/#findComment-514878 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.