Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> PHP PDO w innych plikach.
Utilaft
post
Post #1





Grupa: Zarejestrowani
Postów: 39
Pomógł: 0
Dołączył: 19.01.2013

Ostrzeżenie: (10%)
X----


Witam.

W indexie includuję sobie config, a w configu mam takie cośik;

  1. $hostdb = 'localhost';
  2. $namedb = 'uti';
  3. $userdb = 'uti';
  4. $passdb = '********';
  5.  
  6.  
  7. try {
  8. $db = new PDO("mysql:host=$hostdb; dbname=$namedb", $userdb, $passdb);
  9. }
  10. catch(PDOException $e) {
  11. echo 'Wystąpił błąd w połączeniu: ' . $e->getMessage();
  12. }
  13.  


problem w tym, że jak chcę w innym pliku zrobić zapytanie ($lala = exec("INSERT INTO users SET login = '$login', password = '$password', email = '$email', date = now()")(IMG:style_emoticons/default/wink.gif)

to po prostu nie widzi mi zmiennej $db z config.

Jak mogę to sensownie rozwiązać?

Pozdrawiam ; ))
Powód edycji: [Spawnm]:
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
Utilaft
post
Post #2





Grupa: Zarejestrowani
Postów: 39
Pomógł: 0
Dołączył: 19.01.2013

Ostrzeżenie: (10%)
X----


No variable bla.. że nie znaleziono zmiennej, jeśli poproszę o wyświetlenie $db w innym pliku.

Notice: Undefined variable: db in E:\xampp\htdocs\class\UserManager.class.php on line 38

Fatal error: Call to a member function query() on a non-object in E:\xampp\htdocs\class\UserManager.class.php on line 38



@up, po dodaniu returna, takie cosik:

Warning: include_once(MainPage.class.php): failed to open stream: No such file or directory in E:\xampp\htdocs\config.php on line 31

Warning: include_once(): Failed opening 'MainPage.class.php' for inclusion (include_path='.;E:\xampp\php\PEAR') in E:\xampp\htdocs\config.php on line 31

Fatal error: Class 'MainPage' not found in E:\xampp\htdocs\index.php on line 10


Załączam plik config.php, MainPage.class.php, UserManager.class.php


http://wklej.to/H53Ht




Go to the top of the page
+Quote Post

Posty w temacie


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

 



RSS Aktualny czas: 12.10.2025 - 05:42