Witam,

Utworzyłem system logowania w smarty i PEAR.

Klasa łącząca się z bazą danych
  1. class DBManager {
  2. private static $DBConnection = null;
  3.  
  4. private function __construct() {
  5. }
  6.  
  7. private function DNSInit() {
  8. return ''.DB_TYPE.'://'.DB_USER.':'.DB_PASS.'@tcp+'.DB_SERVER.'/'.DB_NAME.'';
  9. }
  10.  
  11. public function Init() {
  12. if(PEAR::isError(self::$DBConnection = MDB2::connect(self::DNSInit()))) {
  13. throw new Exception(self::$DBConnection->getMessage(), self::$DBConnection->getCode());
  14. }
  15. }
  16.  
  17. public function Query($queryString) {
  18. if(self::$DBConnection) {
  19. if(PEAR::isError($result = self::$DBConnection->Query($queryString))) {
  20. throw new Exception ($result->getMessage(), $result->getCode());
  21. return $result;
  22. }
  23. }
  24. }
  25.  
  26. public function Transaction($type) {
  27. $sqlquery = $type;
  28. if(PEAR::isError($result = self::$DBConnection->Query($sqlquery))) {
  29. throw new Exception ('Przesłanie zapytania nie powiodło się');
  30. } else {
  31. if(self::$DBConnection->affectedRows() < 0) {
  32. throw new Exception ('Odebranie wyników zapytania nie powiódł się');
  33. }
  34. }
  35. return TRUE;
  36. }
  37. }


Klasa gdzie pobierany jest użytkownik i hasło
  1. class User {
  2. private $_Id;
  3. private $_DNS;
  4. private $_Password;
  5. private $_Email;
  6.  
  7. public function __construct($userdata = NULL) {
  8. foreach ($userdata as $key => $value) {
  9. switch (strtolower($key)) {
  10. case 'usr_id';
  11. $this->setId($value);
  12. break;
  13. case 'usr_email';
  14. $this->setEmail($value);
  15. break;
  16. }
  17. }
  18. $this->setDNS(DNSInit());
  19. }
  20.  
  21. public function setId($id) {
  22. if($id <> NULL) {
  23. $this->_Id = $id;
  24. return TRUE;
  25. } else {
  26. return FALSE;
  27. }
  28. }
  29.  
  30. public function getId() {
  31. return $this->_Id;
  32. }
  33.  
  34. public function authorize ($userLogin, $userPassword) {
  35. DBManager::Transaction('BEGIN');
  36. $sqlquery = "SELECT * FROM users WHERE USR_id = '".$userLogin."' ";
  37. $result = DBManager::Query($sqlquery);
  38. if($user = $result->fetchRow(DB_FETCHMODE_ASSOC)) {
  39. if($user['USR_Password'] == $userPassword) {
  40. DBManager::Transaction('COMMIT');
  41. return TRUE;
  42. }
  43. }
  44. DBManager::Transaction('ROLLBACK');
  45. throw new Exception ('Logowanie nieudane');
  46. }
  47.  
  48. public function Logon($login, $password) {
  49. self::authorize($login, $password);
  50. $sqlquery = "SELECT * FROM users WHERE usr_id = '".$login."' ";
  51. $result = DBManager::Query($sqlquery);
  52. if($userdata = $result->fetchRow(DB_FETCHMODE_ASSOC)) {
  53. $currentUser = new User($userdata);
  54. return $currenrUser;
  55. } else {
  56. throw new Exception ('Poranie danych nie powidło się');
  57. }
  58. }
  59. }


Plik index.php
  1. require_once 'config/application.inc.php';
  2.  
  3.  
  4. require_once 'header.php';
  5.  
  6. if(!isSet($_POST['username']) && !isSet($_POST['password'])) {
  7. $smarty->display('logon.tpl');
  8. } else {
  9. try {
  10. DBManager::Init();
  11. User::Logon($_POST['username'], $_POST['password']);
  12. $smarty->display('index.tpl');
  13. } catch (Exception $error) {
  14. $smarty->display('error.tpl');
  15. echo $error->getMessage();
  16. }
  17. }
  18.  
  19.  
  20. require_once 'footer.php';


w logon.tpl jest to zwykły formularz

i teraz jak wpisze login i hasło pojawia się błąd:

Fatal error: Call to undefined function: MDB2_Driver_mysql::affectedRows(). in C:\xampp\php\PEAR\MDB2.php on line 1936

Na kompie zainstalownay mam phpMyAdmin 1.7.3

Z góry dzięki za odpowiedź,
Jacek