Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [MySQL] multi_query(), Brak odpowiedzi na inne zapytania po multi_query.
Tomplus
post 5.09.2015, 14:12:02
Post #1





Grupa: Zarejestrowani
Postów: 1 879
Pomógł: 230
Dołączył: 20.03.2005
Skąd: Będzin

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


Mam taką prostą funkcję w klasie.
  1. public multi($sql)
  2. {
  3. if($this->lacz->multi_query($sql)) return true;
  4. else return false;
  5. }


Funkcja działa. Wykonuje multi zapytania.

Jednak powoduje ona błąd który nie mogę sprostać, wykorzystując ją gdzie indziej.

  1. $this->db->policz("SELECT id FROM informacje"); //wynik prawidłowy
  2. $this->db->multi($dodajDane); //prawidłowo dodane rekordy (sprawdzałem w PMAdmin)
  3. $this->db->policz("SELECT id FROM informacje"); // wynik false - 0


W każdym razie przed wywołaniem funkcji multi, mogłem korzystać ze wszystkich funkcji klasy, a po wywołaniu mam same odpowiedzi false. Gdzie leży problem?
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 2)
Comandeer
post 5.09.2015, 14:35:23
Post #2





Grupa: Zarejestrowani
Postów: 1 268
Pomógł: 254
Dołączył: 11.06.2009
Skąd: Świętochłowice

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


Warto przeglądać komentarze w manualu wink.gif http://php.net/manual/en/mysqli.multi-query.php#102837


--------------------
Go to the top of the page
+Quote Post
Tomplus
post 5.09.2015, 15:14:33
Post #3





Grupa: Zarejestrowani
Postów: 1 879
Pomógł: 230
Dołączył: 20.03.2005
Skąd: Będzin

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


Czytałem, stosowałem, ale nie pomaga:

  1. public function test() {
  2. echo "<pre>";
  3. $q = $this->lacz->query("SELECT count(id) FROM informacje");
  4. var_dump($q);
  5. $res = $q->fetch_array();
  6. echo "
  7. 1=> ".$res[0];
  8. if ($this->lacz->multi_query("SELECT id FROM informacje;SELECT id FROM informacje;")) echo "
  9. 2=> true"; else echo "
  10. 2=> false";
  11. while ($this->lacz->next_result()) {if (!$this->lacz->more_results()) break;}
  12. $q1 = $this->lacz->query("SELECT count(id) FROM informacje");
  13. var_dump($q1);
  14. $res = $q1->fetch_array();
  15.  
  16. echo "
  17. 3=> ".$res[0];
  18. echo "</pre>";
  19. }
  20.  



a odpowiedzi:

Kod
object(mysqli_result)#3 (5) {
  ["current_field"]=>
  int(0)
  ["field_count"]=>
  int(1)
  ["lengths"]=>
  NULL
  ["num_rows"]=>
  int(1)
  ["type"]=>
  int(0)
}

        1=> 8194bool(true)

        2=> falsebool(false)


Fatal error:  Call to a member function fetch_array() on a non-object...


a powinno być: 3=> 8194


Aha... zrzut var_dump($this->lacz);
Kod
object(mysqli)#2 (19) {
["affected_rows"]=> int(0)
["client_info"]=> string(79) "mysqlnd 5.0.11-dev - 20120503"
["client_version"]=> int(50011)
["connect_errno"]=> int(0)
["connect_error"]=> NULL
["errno"]=> int(0)
["error"]=> string(0) ""
["error_list"]=> array(0) { }
["field_count"]=> int(0)
["host_info"]=> string(37) "localhost via TCP/IP"
["info"]=> NULL
["insert_id"]=> int(0)
["server_info"]=> string(18) "5.5.43-MariaDB-log"
["server_version"]=> int(50543)
["stat"]=> string(157) "Uptime: 1593698 Threads: 8 Questions: 1080197386 Slow queries: 98149 Opens: 36678366 Flush tables: 2 Open tables: 1024 Queries per second avg: 677.793"
["sqlstate"]=> string(5) "00000"
["protocol_version"]=> int(10)
["thread_id"]=> int(21916318)
["warning_count"]=> int(0) }
Więc połączenie z bazą jest prawidłowe.

Ten post edytował Tomplus 5.09.2015, 15:25:25
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: 13.08.2025 - 23:19