Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

 
Reply to this topicStart new topic
> [php][mysqli] multi_query i query
therias
post
Post #1





Grupa: Zarejestrowani
Postów: 8
Pomógł: 0
Dołączył: 25.05.2008

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


Witam.
Mam problem, gdy mój skrypt wygląda tak:
  1. <?php
  2. //..pomijam polaczenie z baza itd...
  3. $db->multi_query("INSERT........; INSERT............; UPDATE...............;"); //przykladowe zapytanie
  4. //.....
  5. $db->query("SELECT........."); //wybranie rekordow
  6. ?>

w moim przypadku przykladowe zapytanie to dodanie firmy do katalogu, powiazanie z kategoriami, +1 do ilosci firm w katalogu. Później wybieram rekordy by zobaczyc zmiany.... i tu pojawia sie błąd:

Fatal error: Call to a member function fetch_assoc() on a non-object in /home/kontko/ftp/test/test.php on line 23

Czym to może być spowodowane? Może trzeba jakoś "zresetować" result z poprzedniego zapytania?
Help! (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
Pozdrawiam
Go to the top of the page
+Quote Post
kosmos
post
Post #2





Grupa: Zarejestrowani
Postów: 367
Pomógł: 17
Dołączył: 4.03.2008

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


Za mało pokazałeś (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

Wklej normalnie kod i pokaż linijke 23
Go to the top of the page
+Quote Post
therias
post
Post #3





Grupa: Zarejestrowani
Postów: 8
Pomógł: 0
Dołączył: 25.05.2008

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


Za duzo by wklejać (IMG:http://forum.php.pl/style_emoticons/default/tongue.gif) generalnie to wyglada tak: Mam klase Firma, gdzie mam statyczna metode
  1. <?php
  2. static public function addFirma($dane, $foto_title, $logo) {
  3. global $db;
  4.  
  5. $query = "INSERT INTO ".TAB_KF_FIR." VALUES (null, '".$dane['nazwa']."', '".$dane['miasto']."', '".$dane['kodp']."', '".$dane['adres']."', '".$dane['tel_dom']."', '".$dane['tel_kom']."', '".$dane['tel_fax']."', '".$dane['slowa_klucz']."', '".$dane['email']."', '".$dane['www']."', '".nl2br($dane['opis'])."', '".$dane['osoba']."');
  6. INSERT INTO ".TAB_KF_CZE." VALUES (LAST_INSERT_ID());";
  7.  
  8. if(!empty($dane['idKat1']) || !empty($dane['idKat2']) || !empty($dane['idKat3'])) {
  9. $query .= "INSERT INTO ".TAB_KF_KAFI." VALUES "
  10. .($dane['idKat1']?"(LAST_INSERT_ID(), ".$dane['idKat1']."),":'')
  11. .($dane['idKat2']?"(LAST_INSERT_ID(), ".$dane['idKat2']."),":'')
  12. .($dane['idKat3']?"(LAST_INSERT_ID(), ".$dane['idKat3']."),":'');
  13. $query = substr($query, 0, strlen($query)-1).";";
  14. }
  15.  
  16. if(!empty($logo)) {
  17. rename('photos/kf/temp_'.$logo.'_m.jpg', 'photos/kf/'.$foto_title.'_'.$logo.'_m.jpg');
  18. $query .= "INSERT INTO ".TAB_KF_LOGO." VALUES (LAST_INSERT_ID(), '".$foto_title."_".$_SESSION['logo']."');";
  19. }
  20.  
  21. if($db->multi_query($query)) {
  22. return true;
  23. } else {
  24. return false;
  25. }
  26. }
  27. ?>

Po dodaniu ma sie pokazac komunikat i tabela z firmami:
  1. <?php
  2. $res = $db->query("SELECT * FROM ".TAB_KF_FIR.";");
  3. $rek = $res->fetch_assoc(); //to jest linijka 23 :)
  4. //......
  5. ?>
Go to the top of the page
+Quote Post
tomeksobczak
post
Post #4





Grupa: Zarejestrowani
Postów: 139
Pomógł: 10
Dołączył: 6.07.2007
Skąd: opole

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


Cytat(therias @ 18.06.2008, 20:17:46 ) *
Za duzo by wklejać (IMG:http://forum.php.pl/style_emoticons/default/tongue.gif) generalnie to wyglada tak: Mam klase Firma, gdzie mam statyczna metode

Właśnie wkleiłeś 27 linii kodu, a 23 to za dużo?
Go to the top of the page
+Quote Post
therias
post
Post #5





Grupa: Zarejestrowani
Postów: 8
Pomógł: 0
Dołączył: 25.05.2008

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


miałem na myśli gdybym miał wklejać cały kod skryptu (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)
Go to the top of the page
+Quote Post
kosmos
post
Post #6





Grupa: Zarejestrowani
Postów: 367
Pomógł: 17
Dołączył: 4.03.2008

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


Na początek wywal ten global ... zastąp sesją
W OOP broń się od global (IMG:http://forum.php.pl/style_emoticons/default/smile.gif)

Ten post edytował kosmos 18.06.2008, 19:35:02
Go to the top of the page
+Quote Post
therias
post
Post #7





Grupa: Zarejestrowani
Postów: 8
Pomógł: 0
Dołączył: 25.05.2008

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


sesją? :| Jak mam to niby zrobić?
Go to the top of the page
+Quote Post
nospor
post
Post #8





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




Cytat
Na początek wywal ten global ... zastąp sesją

Cytat
sesją? :| Jak mam to niby zrobić?

Kolega chyba sie przejęzyczył z tą sesją (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg)

Co do problemu:
  1. <?php
  2. $res = $db->query("SELECT * FROM ".TAB_KF_FIR.";");
  3. ?>

Zwraca ci false, znaczy masz blad zapytania. wyswietl sobie blad i zobacz co masz źle
  1. <?php
  2. $res = $db->query("SELECT * FROM ".TAB_KF_FIR.";");
  3. echo $db->error;
  4. ?>
Go to the top of the page
+Quote Post
therias
post
Post #9





Grupa: Zarejestrowani
Postów: 8
Pomógł: 0
Dołączył: 25.05.2008

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


"Commands out of sync; you can't run this command now" :/
Go to the top of the page
+Quote Post
kosmos
post
Post #10





Grupa: Zarejestrowani
Postów: 367
Pomógł: 17
Dołączył: 4.03.2008

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


Cytat(nospor @ 18.06.2008, 22:33:14 ) *
Kolega chyba sie przejęzyczył z tą sesją (IMG:http://forum.php.pl/style_emoticons/default/winksmiley.jpg)


Lubie sesje (IMG:http://forum.php.pl/style_emoticons/default/biggrin.gif)

Serio sory za to ;]
Go to the top of the page
+Quote Post
nospor
post
Post #11





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




Cytat
Commands out of sync; you can't run this command now
no mogles troche pogooglac
http://www.google.com/search?client=opera&...-8&oe=utf-8
wyniki:
http://dev.mysql.com/doc/refman/5.0/en/com...ut-of-sync.html
http://pl2.php.net/manual/en/function.mysql-query.php#82429
http://bugs.php.net/bug.php?id=39727
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 - 05:17