/** * @param int $id * @param PDO $connection */ public function User($id, PDO $connection) { $this->root_id = $GLOBALS['CONFIG']['root_id']; $this->field_name = 'username'; $this->field_id = 'id'; $this->tablename = $GLOBALS['CONFIG']['db_prefix'] . $this->TABLE_USER; $this->result_limit = 1; //there is only 1 user with a certain user_name or user_id databaseData::setTableName($this->TABLE_USER); databaseData::databaseData($id, $connection); $query = "\n SELECT \n id, \n username, \n department, \n phone, \n email, \n last_name, \n first_name, \n pw_reset_code,\n can_add,\n can_checkin\n FROM \n {$GLOBALS['CONFIG']['db_prefix']}user \n WHERE \n id = :id"; $stmt = $connection->prepare($query); $stmt->execute(array(':id' => $this->id)); $result = $stmt->fetch(); list($this->id, $this->username, $this->department, $this->phone, $this->email, $this->last_name, $this->first_name, $this->pw_reset_code, $this->can_add, $this->can_checkin) = $result; }
/** * * **/ function User($id, $connection, $database) { $this->root_id = $GLOBALS['CONFIG']['root_id']; $this->field_name = 'username'; $this->field_id = 'id'; $this->tablename = $GLOBALS['CONFIG']['db_prefix'] . $this->TABLE_USER; $this->result_limit = 1; //there is only 1 user with a certain user_name or user_id databaseData::setTableName($this->TABLE_USER); databaseData::databaseData($id, $connection, $database); $query = "\n SELECT \n id, \n username, \n department, \n phone, \n email, \n last_name, \n first_name, \n pw_reset_code,\n can_add,\n can_checkin\n FROM \n {$GLOBALS['CONFIG']['db_prefix']}user \n WHERE \n id=" . $this->id; $result = mysql_query($query, $this->connection) or die("Error in query: {$query}" . mysql_error()); if (mysql_num_rows($result) > 1) { echo 'Non-unique key DB error'; exit; } list($this->id, $this->username, $this->department, $this->phone, $this->email, $this->last_name, $this->first_name, $this->pw_reset_code, $this->can_add, $this->can_checkin) = mysql_fetch_row($result); mysql_free_result($result); }