Witaj Gościu! ( Zaloguj | Rejestruj )

Forum PHP.pl

> [php] Zmienna w funkcji nie dziala
Bojakki
post
Post #1





Grupa: Zarejestrowani
Postów: 379
Pomógł: 0
Dołączył: 18.08.2004

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


Znalazlem bardzo fajny system cachowania zapytan:
http://webcity.pl/webcity/cachowanie_zapytan_sql_w_php

Wszytso dziala pieknie i bez problemow procz 1 rzeczy. Mam taki kod:

  1. <?php
  2. require('./sterownix.php');
  3.  
  4.   $sql = new sql;
  5.  
  6.   $sql -> sql_connect('localhost', 'zyx', 'doopah', 'fws');
  7.  
  8.   $sql -> sql_cache('uchwyt');
  9.   $sql -> sql_query('SELECT * FROM config');
  10.  
  11.   while($sql -> sql_fetch_row()){
  12.      echo $sql -> rows[0].' - '.$sql -> rows[1].'<br/>';
  13.   }
  14.   $sql -> sql_cache();
  15.  
  16.   $sql -> sql_close();
  17. ?>


Gdy parametr w $sql -> sql_cache(); zmienie biore ze zmiennej czyli np:

  1. <?php
  2. $sql -> sql_cache($zmienna);
  3. ?>

To nie dziala. Tzn zachowuje sie tak jakby zmienna nie istniala a jest na pewno.

Aha kod funkcji sql_cache wyglada tak:

  1. <?php
  2. function sql_cache($handle = 0){
  3.         if(is_string($handle)){
  4.            if(file_exists(CACHE_DIR.'xxx_'.$handle.'.666')){
  5.               $this -> cache_state   = 1;
  6.               $this -> cache_ptr      = 0;
  7.               $this -> cache_buffer = unserialize(file_get_contents(CACHE_DIR.'xxx_'.$handle.'.666'));
  8.            }else{
  9.               $this -> cache_state = 2;
  10.               $this -> cache_buffer = array();
  11.               $this -> cache_file = CACHE_DIR.'xxx_'.$handle.'.666';
  12.            }      
  13.         }else{
  14.            if($this -> cache_state == 2){
  15.               file_put_contents($this -> cache_file, serialize($this -> cache_buffer));
  16.            }
  17.            $this -> cache_state = 0;
  18.         }
  19.      }
  20. ?>
Go to the top of the page
+Quote Post
 
Start new topic
Odpowiedzi (1 - 3)
Darti
post
Post #2





Grupa: Zarejestrowani
Postów: 1 076
Pomógł: 62
Dołączył: 6.03.2005
Skąd: Wroc

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


A co zawiera zmienna ?
Go to the top of the page
+Quote Post
Bojakki
post
Post #3





Grupa: Zarejestrowani
Postów: 379
Pomógł: 0
Dołączył: 18.08.2004

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


numer skladajacy sie z 1-4 cyfr

Ten post edytował Bojakki 4.05.2009, 18:45:39
Go to the top of the page
+Quote Post
Zyx
post
Post #4





Grupa: Zarejestrowani
Postów: 952
Pomógł: 154
Dołączył: 20.01.2007
Skąd: /dev/oracle

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


W kodzie masz wywołanie is_string(). Po prostu zrzutuj ten numer na stringa i powinno być po problemie:

Kod
$sql -> sql_cache((string)$zmienna);
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: 25.08.2025 - 12:05