Uldeens Posted October 15, 2004 Report Share Posted October 15, 2004 Man datubaze glabajas tris vertibas.(a b c) ka vinas dabut masiva lai es pec tam varu izsaukt echo $a[1]; echo $b[5]; utt.. Zinu ka jau so esu prasijis bet taa arii neierubiijos. Paldies. Link to comment Share on other sites More sharing options...
bubu Posted October 16, 2004 Report Share Posted October 16, 2004 Ja tās trīs vērtības (abc) ir domātas tabulas rindiņas, tad: $res = mysql_query('SELECT * FROM tabula LIMIT 3'); $a = mysql_fetch_row($res); $b = mysql_fetch_row($res); $c = mysql_fetch_row($res); mysql_free_result($res); Link to comment Share on other sites More sharing options...
Venom Posted October 16, 2004 Report Share Posted October 16, 2004 ja kolonnās a,b,c - tad $data=mysql_fetch_assoc($res); $a=$data['a']'; $b=$data['b']'; $c=$data['c']'; Link to comment Share on other sites More sharing options...
bubu Posted October 17, 2004 Report Share Posted October 17, 2004 Venom, un ko tad nozīmēs $a[1], $b[5] ? ;) Link to comment Share on other sites More sharing options...
Venom Posted October 18, 2004 Report Share Posted October 18, 2004 pie mysql_fetch_assoc neko pie mysql_fetch_array() kolonnu vērtības tiks nodotas (precīzāk - nokopētas, ar ko arī šī funkcija ir lēnāka) gan caur asociatīviem indeksiem (kolonnu nosaukumi) - kolonnu kārtība vaicājumā nav no savara; gan kā numerēti indeksi, indeksēti ar naturāliem skaitļiem pēc kārtas (1,2...) - svarīga kolonnu kārtība vaicājumā. Link to comment Share on other sites More sharing options...
bubu Posted October 18, 2004 Report Share Posted October 18, 2004 Nu bet Venom, pēc tava piemēra: $data=mysql_fetch_assoc($res); $a=$data['a']'; kas tagad būs $a[1], kā tika prasīts? ;) Link to comment Share on other sites More sharing options...
Venom Posted October 18, 2004 Report Share Posted October 18, 2004 ja nemaldos, nekā. bet tāpēc jau bija mans pieņēmums, ka a,b,c ir att. kolonnu, nevis rindu nosaukumi un padoms, ka labāk izmantot *_assoc Link to comment Share on other sites More sharing options...
Valters Posted October 19, 2004 Report Share Posted October 19, 2004 (precīzāk - nokopētas, ar ko arī šī funkcija ir lēnāka) Lai nesabiedētu tautu, šeit noderētu izvilkums no php dokumentācijas: An important thing to note is that using mysql_fetch_array() is not significantly slower than using mysql_fetch_row(), while it provides a significant added value. Link to comment Share on other sites More sharing options...
Venom Posted October 19, 2004 Report Share Posted October 19, 2004 nu jau trešā funkcija izvilkta gaismā ;) Link to comment Share on other sites More sharing options...
Roze Posted October 19, 2004 Report Share Posted October 19, 2004 (precīzāk - nokopētas, ar ko arī šī funkcija ir lēnāka) Lai nesabiedētu tautu, šeit noderētu izvilkums no php dokumentācijas: An important thing to note is that using mysql_fetch_array() is not significantly slower than using mysql_fetch_row(), while it provides a significant added value. No tiem pashiem komentaariem (tests gan nedaudz pavecs, bet manupraat atbilst patiesiibai): Benchmark on a table with 38567 rows: mysql_fetch_array MYSQL_BOTH: 6.01940000057 secs MYSQL_NUM: 3.22173595428 secs MYSQL_ASSOC: 3.92950594425 secs mysql_fetch_row: 2.35096800327 secs mysql_fetch_assoc: 2.92349803448 secs As you can see, it's twice as effecient to fetch either an array or a hash, rather than getting both. it's even faster to use fetch_row rather than passing fetch_array MYSQL_NUM, or fetch_assoc rather than fetch_array MYSQL_ASSOC. Don't fetch BOTH unless you really need them, and most of the time you don't. Link to comment Share on other sites More sharing options...
Venom Posted October 19, 2004 Report Share Posted October 19, 2004 no diviem ļaunumiem izvēlos assoc, jo vienmēr vēršos pie kolonnām pēc to nosaukumiem, jo mainu to pozīcijas gan bd, gan qvērijos - un tamdēļ arī izmantoju INSERT/UPDATE ar SET, nevis VALUES() Link to comment Share on other sites More sharing options...
Valters Posted October 20, 2004 Report Share Posted October 20, 2004 Hmm, ja testa rezultāti tiešām atbilst patiesībai, tad tas nu nepavisam nav "insignificant" un šis teksts doķos ir maldinošs. Būs jāpainteresējas kādās mailinglistēs. Link to comment Share on other sites More sharing options...
Venom Posted October 21, 2004 Report Share Posted October 21, 2004 šobrīd lielākā pieejama db tabula ir pāri 8000 ierakstu (toties ar gariem blobiem) tests: mysql_connect('localhost','username','password');mysql_query('use db); $res=mysql_query('select * from tabula'); $start=array_sum(explode(' ',microtime())); while(mysql_fetch_array($res)); echo array_sum(explode(' ',microtime()))-$start.' array<br />'; mysql_data_seek($res,0); $start=array_sum(explode(' ',microtime())); while(mysql_fetch_assoc($res)); echo array_sum(explode(' ',microtime()))-$start.' assoc<br />'; mysql_data_seek($res,0); $start=array_sum(explode(' ',microtime())); while(mysql_fetch_row($res)); echo array_sum(explode(' ',microtime()))-$start.' row<br />'; Viens no rezultātiem (refrešojot mazliet mainās, bet tendence saglabājas): 0.088567018508911 array 0.048879146575928 assoc 0.042423963546753 row Kā jau teicu agrāk, fleksibilitātes dēļ tomēr izvēlos assoc. Pagaidām neko _tādu_ weba vajadzībām no lielākām db nav nācies atlasīt (zinātnes vajadzībām tiek bliezts pa tiešo mysql shellā). Link to comment Share on other sites More sharing options...
Venom Posted October 21, 2004 Report Share Posted October 21, 2004 pamatīgāka tabula: [COUNT(*)] => 156529 2.2445039749146 array 1.3798410892487 assoc 1.0968980789185 row Link to comment Share on other sites More sharing options...
bubu Posted October 21, 2004 Report Share Posted October 21, 2004 Kāda php/mysql versija? Link to comment Share on other sites More sharing options...
Recommended Posts