Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Problem z PDO
tymczasowe
post 4.10.2012, 17:28:16
Post #1





Grupa: Zarejestrowani
Postów: 4
Pomógł: 0
Dołączył: 27.07.2012

Ostrzeżenie: (0%)
-----


Witam mam mały problem z PDO a mianowicie z klasa userAction wygląda ona następująco:
  1. class UserAction {
  2.  
  3. public function isLogged()
  4. {
  5. if($_SESSION['isLogged'])
  6. {
  7. return true;
  8. }
  9. else
  10. {
  11. return false;
  12. }
  13. }
  14.  
  15. public function getUserData()
  16. {
  17. if($this -> isLogged())
  18. {
  19. $query = prepare("SELECT COUNT(*) FROM ".$table_prefix."users WHERE userId = :userId");
  20. $params = array( "userId" => $this -> userID());
  21. $stmt -> execute($params);
  22.  
  23. while($row = $stmt -> fetch())
  24. {
  25. echo $row['userId'];
  26. }
  27. }
  28. else
  29. {
  30. _e('pre','Już jesteś zalogowany!.');
  31. }
  32. }
  33.  
  34. public function userID()
  35. {
  36. $_SESSION['userId'] = $userId;
  37. return $userId;
  38. }
  39. }


i wywołanie kodu:
  1. <?php
  2. try
  3. {
  4. define('DS',DIRECTORY_SEPARATOR);
  5. require_once dirname(__FILE__).DS."..".DS."system".DS."system.php";
  6. if (!defined('SITE_PATCH') or !constant('SITE_PATCH')) die(_e('pre','Dostęp bezpośredni niedozwolone wtargnięcie!'));
  7. $PDO = new PDO($DSN, $Username, $Password);
  8. $PDO -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
  9. require_once SYSTEM.'sitecore'.ext;
  10.  
  11. if(file_exists( THEMES.THEME.'/header'.ext ) && file_exists( THEMES.THEME.'/footer'.ext ))
  12. {
  13. require_once THEMES.THEME.'/header'.ext;
  14.  
  15. $UserAction = new UserAction;
  16.  
  17. if($UserAction -> isLogged())
  18. {
  19. $UserAction -> getUserData();
  20. }
  21. else
  22. {
  23. $SystemAction -> redirect('index');
  24. }
  25. require_once THEMES.THEME.'/footer'.ext;
  26. }
  27. else
  28. {
  29. _e('pre',"Nie można wczytać szablonu ".THEME." !.");
  30. }
  31.  
  32. require_once TEMPLATES.'footer'.ext;
  33. }
  34. catch(PDOException $error)
  35. {
  36. _e('pre',"Połączenie nie mogło zostać utworzone: ".$error -> getMessage()." !.");
  37. }
  38. ?>


a błąd to:
Fatal error: Call to undefined function prepare() in /virtual/e/r/ervstudio.ugu.pl/system/class/UserAction.php on line 25
Co jest nie tak ?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 2)
nospor
post 4.10.2012, 17:31:32
Post #2





Grupa: Moderatorzy
Postów: 36 557
Pomógł: 6315
Dołączył: 27.12.2004




prepare jest funkcji obiektu PDO a nie samodzielną funkcją... przenosze na przedszkole


--------------------

"Myśl, myśl, myśl..." - Kubuś Puchatek || "Manual, manual, manual..." - Kubuś Programista
"Szukaj, szukaj, szukaj..." - Kubuś Odkrywca || "Debuguj, debuguj, debuguj..." - Kubuś Developer

Go to the top of the page
+Quote Post
szalek01
post 4.10.2012, 22:53:51
Post #3





Grupa: Zarejestrowani
Postów: 129
Pomógł: 17
Dołączył: 17.09.2012

Ostrzeżenie: (0%)
-----


Sprawdź jak tu jest użyte ($pdo -> prepare) http://pl.wikibooks.org/wiki/PHP/Biblioteka_PDO

Ten post edytował szalek01 4.10.2012, 22:54:05


--------------------
PDO nie gryzie....
Go to the top of the page
+Quote Post

Reply to this topicStart new topic
1 Użytkowników czyta ten temat (1 Gości i 0 Anonimowych użytkowników)
0 Zarejestrowanych:

 



RSS Wersja Lo-Fi Aktualny czas: 14.08.2025 - 03:27