![]() |
![]() ![]() |
![]() |
![]()
Post
#1
|
|
![]() Grupa: Zarejestrowani Postów: 176 Pomógł: 0 Dołączył: 27.06.2002 Skąd: Stalowa Wola Ostrzeżenie: (0%) ![]() ![]() |
Witam.
Wlasnie zaczalem przygode z ADODB. I mam takie pytanka: 1.Jak wyswietlic liczbe wykonanych zapytac ![]() Ponizej kod mojego pliku index.php
2. Jak zoptymalizowac powyzszy kod aby byl jak najmniej zapytan do bazy ? 3.Ponadto chcialbym wiedziec czy ADODB ma jakas klase do porcjowania wynikow bo np. EZSql ma ma bardzo zaawansowana klase EZREsults ? Jesli ma to czy moglby ktos podac przyklad jej uzycia ![]() Z gory dzieki za pomoc. Ten post edytował stal-sw 10.04.2005, 17:43:40 -------------------- |
|
|
![]()
Post
#2
|
|
![]() Grupa: Zarejestrowani Postów: 740 Pomógł: 15 Dołączył: 23.08.2004 Skąd: Poznań Ostrzeżenie: (0%) ![]() ![]() |
ad 1. Za kazdym razem gdy wykonujesz $rs = $DB->GetAll(); Zwiększaj wartosc licznika $liczba_wykonanych_zapytan++, a na koniec wyswietl wartosc tej zmiennej. lub poczytaj w dokumentacji adodb na temat fnExecute and fnCacheExecute.
Kod Examples of fnExecute Here is an example of using fnExecute, to count all cached queries and non-cached queries, you can do this: # $db is the connection object function CountExecs($db, $sql, $inputarray) { global $EXECS; if (!is_array(inputarray)) $EXECS++; # handle 2-dimensional input arrays else if (is_array(reset($inputarray))) $EXECS += sizeof($inputarray); else $EXECS++; } # $db is the connection object function CountCachedExecs($db, $secs2cache, $sql, $inputarray) { global $CACHED; $CACHED++; } $db = NewADOConnection('mysql'); $db->Connect(...); $db->fnExecute = 'CountExecs'; $db->fnCacheExecute = 'CountCachedExecs'; : : # After many sql statements:` printf("<p>Total queries=%d; total cached=%d</p>",$EXECS+$CACHED, $CACHED); The fnExecute function is called before the sql is parsed and executed, so you can perform a query rewrite. If you are passing in a prepared statement, then $sql is an array (see Prepare). The fnCacheExecute function is only called if the recordset returned was cached. The function parameters match the Execute and CacheExecute functions respectively, except that $this (the connection object) is passed as the first parameter. Since ADOdb 3.91, the behaviour of fnExecute varies depending on whether the defined function returns a value. If it does not return a value, then the $sql is executed as before. This is useful for query rewriting or counting sql queries. On the other hand, you might want to replace the Execute function with one of your own design. If this is the case, then have your function return a value. If a value is returned, that value is returned immediately, without any further processing. This is used internally by ADOdb to implement LogSQL() functionality. ad 2. Brak czasu ad 3. Mysle, ze chodzi ci o SelectLimit(); Kod SelectLimit($sql,$numrows=-1,$offset=-1,$inputarr=false)
Returns a recordset if successful. Returns false otherwise. Performs a select statement, simulating PostgreSQL's SELECT statement, LIMIT $numrows OFFSET $offset clause. In PostgreSQL, SELECT * FROM TABLE LIMIT 3 will return the first 3 records only. The equivalent is $connection->SelectLimit('SELECT * FROM TABLE',3). This functionality is simulated for databases that do not possess this feature. And SELECT * FROM TABLE LIMIT 3 OFFSET 2 will return records 3, 4 and 5 (eg. after record 2, return 3 rows). The equivalent in ADOdb is $connection->SelectLimit('SELECT * FROM TABLE',3,2). Note that this is the opposite of MySQL's LIMIT clause. You can also set $connection->SelectLimit('SELECT * FROM TABLE',-1,10) to get rows 11 to the last row. The last parameter $inputarr is for databases that support variable binding such as Oracle oci8. This substantially reduces SQL compilation overhead. Below is an Oracle example: $conn->SelectLimit("SELECT * FROM TABLE WHERE COND=:val", 100,-1,array('val'=> $val)); The oci8po driver (oracle portable driver) uses the more standard bind variable of ?: $conn->SelectLimit("SELECT * FROM TABLE WHERE COND=?", 100,-1,array('val'=> $val)); Ron Wilson reports that SelectLimit does not work with UNIONs. -------------------- bigZbig (Zbigniew Heintze) | blog.heintze.pl
|
|
|
![]() ![]() |
![]() |
Wersja Lo-Fi | Aktualny czas: 27.06.2025 - 06:59 |