Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MSSQL][PHP] błąd w pobieraniu danych, Dawniej: zmiana typu zmiennej
matyskiewicz
post
Post #1





Grupa: Zarejestrowani
Postów: 184
Pomógł: 3
Dołączył: 6.10.2006
Skąd: Poznań

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


Podczas rozwiązywania problemu, udało mi się ustalić iż zmienia sie typ zmiennej
Dlaczego tak się dzieje i jak mogę zwrócić int?

  1. public function checkURL()
  2. {
  3. $this -> url = isset($_GET['page']) ? $_GET['page'] : Null;
  4. $this -> resultURL = NULL;
  5.  
  6. $db = NewADOConnection($this -> db());
  7. $db -> debug = true;
  8. $db -> SetFetchMode(ADODB_FETCH_ASSOC);
  9. $this -> checkURL = $db -> GetArray('SELECT id, url FROM section WHERE status > 0');
  10. $db -> Close();
  11.  
  12. for ($i=0; $i < sizeof($this -> checkURL); $i++)
  13. {
  14. #jezeli istnieje zwraca true
  15. if (strstr($this -> checkURL[$i]['url'], $this -> url))
  16. $this -> urlID = $this -> checkURL[$i]['id'];
  17. }
  18.  
  19. #NAJCIEKAWSZE =====================================================
  20.  
  21. echo'typ0: '.gettype($this -> urlID); //string
  22.  
  23. $this -> goodURL = settype($this -> urlID, "integer");
  24. echo'typ1: '.gettype($this -> goodURL); //bool
  25. return $this -> urlID;
  26.  
  27. }
  28.  
  29. public function dataFromStaticpage()
  30. {
  31. $this -> goodURL = settype($this -> checkURL(), "integer");
  32. echo'typ2: '.gettype($this -> goodURL); //bool
  33.  
  34. if($this -> goodURL !== NULL)
  35. {
  36.  
  37. $db = NewADOConnection($this -> db());
  38. $db -> debug = true;
  39. $db -> SetFetchMode(ADODB_FETCH_ASSOC);
  40. $resulturl = $db -> GetArray('SELECT * FROM section WHERE id = '.$this -> goodURL);
  41. $db -> Close();
  42.  
  43. echo '<pre>';
  44. print_r($resulturl);
  45. echo '</pre>';
  46. }
  47. else
  48. {
  49. echo 'brak strony';
  50. }
  51. }


  1. typ0: string
  2. typ1: boolean
  3. typ2: boolean


Ten post edytował matyskiewicz 7.04.2010, 12:48:32
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 4)
ziqzaq
post
Post #2





Grupa: Zarejestrowani
Postów: 428
Pomógł: 128
Dołączył: 17.06.2007

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


Cytat
Dlaczego tak się dzieje i jak mogę zwrócić int?

1. Sprawdź w manualu co zwraca settype (IMG:style_emoticons/default/smile.gif)
2.
  1. $this -> goodURL = (int) $this -> urlID;

Go to the top of the page
+Quote Post
matyskiewicz
post
Post #3





Grupa: Zarejestrowani
Postów: 184
Pomógł: 3
Dołączył: 6.10.2006
Skąd: Poznań

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


Ok, dzięki. Teraz poprawiłem:

  1. public function dataFromStaticpage()
  2. {
  3. $this -> goodURL = (int)$this -> checkURL(); //id
  4.  
  5. if($this -> goodURL !== NULL)
  6. {
  7. $db = NewADOConnection($this -> db());
  8. $db -> debug = true;
  9. $db -> SetFetchMode(ADODB_FETCH_ASSOC);
  10. $resulturl = $db -> GetArray('SELECT * FROM section WHERE id = '.$this -> goodURL);
  11. $db -> Close();
  12.  
  13. echo '<pre>';
  14. print_r($resulturl);
  15. echo '</pre>';
  16. }

lecz nadal mam bład:
  1. Warning: mysqli_query() expects parameter 1 to be mysqli, boolean given in C:\srv\xampp\htdocs\xxx\app\lib\adodb\drivers\adodb-mysqli.inc.php on line 695
  2. Query: SELECT * FROM section WHERE id = 2 failed.
  3. 0:
  4.  
  5. ADOConnection._Execute(SELECT * FROM section WHERE id = 2, false) % line 1012, file: adodb.inc.php
  6. ADOConnection.Execute(SELECT * FROM section WHERE id = 2, false) % line 1543, file: adodb.inc.php
  7. ADOConnection.GetArray(SELECT * FROM section WHERE id = 2) % line 36, file: staticpage.php
  8. modelStaticpage.dataFromStaticpage(zasady, null) % line 8, file: staticpage.php
  9. controllerStaticpage.fromModelStaticpage() % line 14, file: staticpage.php



lecz po zmianie:
  1. public function dataFromStaticpage()
  2. {
  3. $this -> goodURL =2; //id

Wszystko jest ok.
Go to the top of the page
+Quote Post
mortus
post
Post #4





Grupa: Zarejestrowani
Postów: 2 178
Pomógł: 596
Dołączył: 25.09.2009
Skąd: Piwniczna-Zdrój

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


Sprawdź na samym początku co zwraca $this->checkURL() za pomocą:
  1. var_dump($this->checkURL());


Ten post edytował mortus 7.04.2010, 15:56:00
Go to the top of the page
+Quote Post
ziqzaq
post
Post #5





Grupa: Zarejestrowani
Postów: 428
Pomógł: 128
Dołączył: 17.06.2007

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


~mortus:
W sumie w debugu widać, że wartość jest już ok.

Wygląda jakby drugie połączenie z bazą zawodziło i zamiast obiektu połączenia przekazywało FALSE.
Z debugu widać, że zapytanie jest prawidłowe.
Może spróbuj wykonać te operacje używając czystego mysqli?
Go to the top of the page
+Quote Post

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: 24.08.2025 - 01:36