I currently have the below construct to create a Member object:
class Member{
private $member_id = 0;
private $name, $surname, $email;
public function __construct(){}
public function construct($conn, $param_select = '*', $param_member_id){
$query_rs_this = $conn->prepare('SELECT :select FROM members WHERE
member_id = :member_id
ORDER BY members.surname');
$query_rs_this->execute(array(':select' => $param_select, ':member_id' => $param_member_id));
$rs_this = $query_rs_this->fetch(PDO::FETCH_ASSOC);
$query_rs_this->closeCursor();
foreach($rs_this as $key => $value){
$this->$key = $value;
}
unset($key);
}
I would like to pass a string containing the columns (field names) which should be selected from the database. Currently I am using this:
$temp = new Member();
$select = "name, surname, email";
$temp->construct($db_conn, $select, 1);
Where $select is the string containing the fields names.
As it stands, I get the following output:
member_id: 0
name:
surname:
email:
?: name, surname, email
This is supposed to be:
member_id: 1
name: John
surname: Doe
email: [email protected]
Thank you in advance for any help.
SELECT :select<= that's a no-no as isexecute(array(':select' => $param_select,. Either select a table or set a variable for it; that is allowed.$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);right after the connection is opened and you will be alerted of errors.