Forum » Izdelava spletišč » PEAR::DB
PEAR::DB

Trubadur ::
Kaj je razlika med fetchinto in fetchrow?
The DB_Result object provides two functions to fetch rows: fetchRow() and fetchInto(). fetchRow() returns the row, NULL on no more data or a DB_Error, when an error occurs. fetchInto() requires a variable, which be will directly assigned by reference to the result row. It will return NULL when result set is empty or a DB_Error too.
The DB_Result object provides two functions to fetch rows: fetchRow() and fetchInto(). fetchRow() returns the row, NULL on no more data or a DB_Error, when an error occurs. fetchInto() requires a variable, which be will directly assigned by reference to the result row. It will return NULL when result set is empty or a DB_Error too.
<?php ... $db = DB::connect($dsn); $res = $db->query("SELECT * FROM mytable"); // Get each row of data on each iteration until // there are no more rows while ($row = $res->fetchRow()) { $id = $row[0]; } // Or: // an example using fetchInto() while ($res->fetchInto($row)) { $id = $row[0]; } ?>
Berite Thomasa!

Ziga Dolhar ::
Razlika je v načinu uporabe :-). Plus fetchinto, kot razumem, ne ustvari kopije zadetka.
https://dolhar.si/

rokpok ::
FetchRow() vrne podatke ki so v vrstici v podatkovni bazi.
Pri FetchInto() moraš podati spremenljivko, kateri potem funkcija dodeli podatke iz vrstice v podatkovni bazi.
Pri tvojem spodnjem primeru lahko narediš naslednje
while ($res->fetchInto($nekaj)) {
$id = $nekaj[0];
}
in bi moglo tudi delati.
Upam, da je to to.
Lp
Pri FetchInto() moraš podati spremenljivko, kateri potem funkcija dodeli podatke iz vrstice v podatkovni bazi.
Pri tvojem spodnjem primeru lahko narediš naslednje
while ($res->fetchInto($nekaj)) {
$id = $nekaj[0];
}
in bi moglo tudi delati.
Upam, da je to to.
Lp

Trubadur ::
uf tenx sleepy!
Ni mi nlo jasn glede tele spremenljivke
Pa sj ti itak že ime pove
Ni mi nlo jasn glede tele spremenljivke


Berite Thomasa!

OwcA ::
Plus fetchinto, kot razumem, ne ustvari kopije zadetka.
Dejansko fetchinto zagotovo ustvari referenco (kar kar nekaj stane, recimo več kot ustvarjanje primitivnega tipa*), medtem ko v drugem primeru ni nujno, da se kopira cel objekt. Lahko se ustvari samo nov alias in poveča število referenc.
* v PHP-ju so dejansko vsi tipi bolj ali manj enaka packarija, le pri objektih se pozna, ako imajo ti veliko atributov
Otroška radovednost - gonilo napredka.
Vredno ogleda ...
Tema | Ogledi | Zadnje sporočilo | |
---|---|---|---|
Tema | Ogledi | Zadnje sporočilo | |
» | [PHP] Podajanje spremenljivke (objekta) ostalim skriptamOddelek: Programiranje | 776 (734) | 680x0 |
» | [C] MySQLOddelek: Programiranje | 2844 (1866) | Tutankhamun |
» | AvatarOddelek: Izdelava spletišč | 1293 (1007) | hihitavc |
» | [PHP]rezultat SQL querija -> dvodimenzionalen ARRAY ??Oddelek: Izdelava spletišč | 1243 (1201) | Ziga Dolhar |
» | sessionsOddelek: Izdelava spletišč | 844 (730) | Taras_Bulba |