Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [PHP][SQL]Call to member function prepare on null
goartur
post
Post #1





Grupa: Zarejestrowani
Postów: 233
Pomógł: 27
Dołączył: 19.10.2014

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


Call to member function prepare on null oto blad ktory otrzymuje. Dodam ze sql ktora napisalem dziala, i wykonuje sie w bazie gdy ja wkleje.
Gdu usune owa funkcje wszystko dziala znowu poprawnie.
Oto ona:
  1. public function setMassagesToRead($userID,$boxID){
  2. $query = $this->_db->prepare("UPDATE chat SET seen = 1 WHERE user_sender= :id AND chatbox_id = :boxID");
  3. $query->bindParam(":id",$userID,PDO::PARAM_STR);
  4. $query->bindParam(":boxID",$boxID,PDO::PARAM_STR);
  5. $query->execute();
  6. }


Mam polaczenie z baza, wszystko dziala gdy usune ta owa funkcje z klasy.
Wiec nie wiem gdzie jest problem.Na stackoverflow wszyscy pisali ze to problem z baza lecz to nie jest mozliwe bo poprostu po wywaleniu tej funkcji wszystko dziala poprawnie. Jakies pomysly?

Ten post edytował goartur 7.04.2016, 11:06:47
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi
nospor
post
Post #2





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




Uwielbiam takie odpowiedzi :/
Tak, jesli ja usuniesz, to ci dziala, bo masz ja zle napisana to logiczne ze dziala gdy ja wywalisz....

A co ja ci moge powiedziec wiecej po takiej ilosci kodu co tu nam dales? Jakas wyrwana z kontekstu funkcja, czort wie jak wyglada reszta kodu... Na chwile obecna $this->_db jest NULLem i tyle w temacie
Go to the top of the page
+Quote Post
goartur
post
Post #3





Grupa: Zarejestrowani
Postów: 233
Pomógł: 27
Dołączył: 19.10.2014

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


Cytat(nospor @ 7.04.2016, 11:16:39 ) *
Uwielbiam takie odpowiedzi :/
Tak, jesli ja usuniesz, to ci dziala, bo masz ja zle napisana to logiczne ze dziala gdy ja wywalisz....

A co ja ci moge powiedziec wiecej po takiej ilosci kodu co tu nam dales? Jakas wyrwana z kontekstu funkcja, czort wie jak wyglada reszta kodu... Na chwile obecna $this->_db jest NULLem i tyle w temacie

No tak sorry, tutaj jest oto funkcja.Ostatnia na samym dole.
setMassagesToRead()

  1. class Server
  2.  
  3. {
  4.  
  5. private $_db;
  6.  
  7. public static $instance;
  8.  
  9. public function __construct(){
  10.  
  11. $this->_db = Connection::getInstance();
  12.  
  13. }
  14.  
  15. public function selectAbleSkills(){
  16.  
  17. $query = $this->_db->prepare("SELECT * FROM skill_type");
  18.  
  19. $query->execute();
  20.  
  21. return $query;
  22.  
  23. }
  24. public function selectExistingStudy(){
  25.  
  26. $query = $this->_db->prepare("SELECT * FROM list_education");
  27.  
  28. $query->execute();
  29.  
  30. return $query;
  31.  
  32. }
  33.  
  34.  
  35.  
  36. public function addMatch($dataMijn, $dataJouw, $dataLike){
  37. $query = $this->_db->prepare("INSERT INTO user_match (user_1,user_2,`match`) VALUES (:dmi,:djo,:dli)");
  38.  
  39. $query->bindParam(":dmi",$dataMijn, PDO::PARAM_INT);
  40. $query->bindParam(":djo",$dataJouw, PDO::PARAM_INT);
  41. $query->bindParam(":dli",$dataLike, PDO::PARAM_INT);
  42. $query->execute();
  43. return $query;
  44. }
  45. /*public function checkIfOtherUserAlreadyMatched($secondUserID,$userID){
  46.   $query = $this->_db->prepare("SELECT * FROM user_match WHERE user_1=122 AND user_2=126 AND `match`=1");
  47.   $query->bindParam(":suid",$secondUserID,PDO::PARAM_STR);
  48.   $query->bindParam(":uid",$userID,PDO::PARAM_STR);
  49.   $query->execute();
  50.   return $query;
  51.   }*/
  52.  
  53. public function loadUserDataForApp($tokenPushID){
  54. $query = $this->_db->prepare("SELECT A.id, A.nameSurname, A.img_id, A.login_type, A.user_type FROM data_user A WHERE A.token_push_id = :token");
  55. $query->bindParam(":token", $tokenPushID, PDO::PARAM_STR);
  56. $query->execute();
  57. return $query;
  58. }
  59.  
  60. public function getChatID($u1,$u2){
  61. $query = $this->_db->prepare("SELECT id FROM chatbox WHERE user_1=:u1 AND user_2=:u2 OR user_1=:u2 AND user_2=:u1");
  62. $query->bindParam(":u1",$u1,PDO::PARAM_STR);
  63. $query->bindParam(":u2",$u2,PDO::PARAM_STR);
  64. $query->execute();
  65. return $query;
  66. }
  67. public function setMassagesToRead($userID,$boxID){
  68. $query = $this->_db->prepare("UPDATE chat SET seen = 1 WHERE user_sender =:id AND chatbox_id =:boxID");
  69. $query->bindParam(":id",$userID,PDO::PARAM_STR);
  70. $query->bindParam(":boxID",$boxID,PDO::PARAM_STR);
  71. $query->execute();
  72. return $query;
  73. }
  74. public static function getInstance()
  75.  
  76. {
  77. if(self::$instance === null)
  78. {
  79. self::$instance = new self();
  80. }
  81. return self::$instance;
  82. }
  83.  
  84.  
  85.  
  86. }


Ten post edytował goartur 7.04.2016, 11:19:40
Go to the top of the page
+Quote Post

Posty w temacie
- goartur   [PHP][SQL]Call to member function prepare on null   7.04.2016, 11:05:31
- - nospor   Blad mowi przeciez wyraznie: $this->_db je...   7.04.2016, 11:07:20
- - goartur   Tak wiem, lecz napisalem ze jesli usune ta funkcje...   7.04.2016, 11:14:08
- - nospor   Uwielbiam takie odpowiedzi :/ Tak, jesli ja usunie...   7.04.2016, 11:16:39
|- - goartur   Cytat(nospor @ 7.04.2016, 11:16:39 ) ...   7.04.2016, 11:19:06
- - kapslokk   Zamień konstruktor na: [PHP] pobierz, plaintext ...   7.04.2016, 11:22:44
- - nospor   Ok. I w jaki sposob odpalasz te funkcje teraz? Bo ...   7.04.2016, 11:26:14
- - goartur   Otrzymuje NULL, nie robie tego obiektowo a statycz...   7.04.2016, 11:28:32
- - nospor   Connection::getInstance(); zwraca ci NULL - tam s...   7.04.2016, 11:37:50
- - goartur   Tak.... Lecz mowie ze kiedy wykomentuje funkcje to...   7.04.2016, 11:39:17
- - Turson   Jaki jest wynik [PHP] pobierz, plaintext echo '...   7.04.2016, 13:18:12
- - goartur   Zwraca object(Server)#8 (1) { ["_db":...   7.04.2016, 13:32:23
- - Turson   No to problem lezy w Connection::getInstance()   7.04.2016, 13:34:53
- - goartur   Nie mam pojecia o co tu chodzi mam 35 funkcji w te...   7.04.2016, 13:43:14
- - kapslokk   Może po prostu pokaż kod Connection::getInstance(...   7.04.2016, 14:20:09
- - goartur   Jasne lap: [PHP] pobierz, plaintext class Connect...   7.04.2016, 14:33:32
- - kapslokk   ... [PHP] pobierz, plaintext var_dump(Connecti...   7.04.2016, 14:39:25
|- - goartur   Cytat(kapslokk @ 7.04.2016, 14:39:25 ...   7.04.2016, 19:39:33
- - nospor   Nie zebym sie jakos specjalnie czzepial, ale juz d...   8.04.2016, 09:21:17


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 Aktualny czas: 13.10.2025 - 06:35