Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> Iterator wynikow zapytań, mysql, php5 nie widzi takiego zapytania
pirat
post
Post #1





Grupa: Zarejestrowani
Postów: 68
Pomógł: 0
Dołączył: 13.05.2003
Skąd: Katowice

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


  1. <?
  2. class MySQLiQueryIterator implements Iterator {
  3.  
  4. protected $link;
  5. protected $query;
  6. protected $key;
  7. protected $valid;
  8. protected $result;
  9.  
  10. public function __construct($link, $query) {
  11. $this->link = $link;
  12. $thisquery = $query;
  13.  
  14. }
  15.  
  16. public function rewind() {
  17. $this->key = 0;
  18.  
  19. if (mysqli_multi_query($this->link, $this->query) ) {
  20. $this->result = mysqli_store_result($this->link);
  21. $this->valid = true;
  22. } else {
  23. $this->result = false;
  24. $this->valid = false;
  25. }
  26. }
  27.  
  28. public function valid() {
  29. //mysqli_more_results() wyprzedza valid() klasy iterator o jedna pozycje
  30. $valid = $this->valid;
  31. $this->valid = mysqli_more_results($this->link);
  32. return $valid;
  33. }
  34.  
  35. public function key() {
  36. return $this->key;
  37. }
  38.  
  39. public function current() {
  40. return $this->result;
  41. }
  42.  
  43. public function next() {
  44. if ($this->result) { mysqli_free_result($thos->result); }
  45. $this->key++;
  46. if (mysqli_next_result($this->link) ) {
  47. $this->result = mysqli_store_result($this->link);
  48. } else {
  49. $this->result = false;
  50. }
  51. }
  52. }
  53.  
  54.  
  55. $db = mysqli_connect('localhost', 'hash', 'haslo', 'thc');
  56.  
  57.  
  58.  
  59. $query = >>>_SQL_
  60. DROP TABLE IF EXISTS users;
  61. CREATE TABLE users(username VARCHAR(50) UNIQUE,
  62. password VARCHAR(50) );
  63. INSERT INTO users VALUES('rasmus', 'zsjdsank');
  64. INSERT INTO users VALUES('zeev', 'zjsdnaka');
  65. SELECT username FROM users;
  66. _SQL_;
  67.  
  68. foreach (new MySQLiQueryIterator($db, $query) as $result) {
  69. if($result) {
  70. while ($row = mysqli_fetch_row($result) ) {
  71. print &#092;"$row[0]n\";
  72. }
  73.  
  74. }
  75. }
  76.  
  77.  
  78.  
  79. ?>


zgłasza że w lini 60:
Parse error: syntax error, unexpected T_SR in c:\wamp\www\phpproject\iterator.php

to jest przyklad z ksiazki ;] php nowe mozliwosci, w sumie nie wiem czemu uzywa sie tutaj >>> (co to operator biotwy jakis?) i wogole zadnych cudzyslowow, jak probowalem wlozyc cudzyslowy, to wogole nie wykonuje tego zapytania (cos zle w klasie? czy co.. ?) wkurzam sie powoli na ta ksiazke, juz z dwa razy blad wychwycilem w tych kodach (literowka, a drugi zla nazwa funkcji), teraz albo nie widze gdzie jest blad(troszke w pospiechu czytam ksiazke, moze cos przeoczylem), albo znowu cos w ksiazce zwalili.

ps. fajne to php 5 (skladnie to z JAVY wyjeli ;] ), ale po 4 mozna sie pogubic ;]
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: 23.08.2025 - 21:28