waplet Posted October 10, 2010 Report Share Posted October 10, 2010 (edited) Kādām nav FP custom query funkcija? Varētu būt tāda interesanta. Tikai ne OOP Edited October 10, 2010 by waplet Quote Link to comment Share on other sites More sharing options...
marrtins Posted October 10, 2010 Report Share Posted October 10, 2010 Koa? Quote Link to comment Share on other sites More sharing options...
codez Posted October 11, 2010 Report Share Posted October 11, 2010 (edited) visi ir nojūgušies vai? Te vienam vajag "php script inside page", te atakal "FP custom query funkcija". P.S. Vai vienkārši palieku vecs un jaunajiem vairs netieku līdzi? Edited October 11, 2010 by codez Quote Link to comment Share on other sites More sharing options...
waplet Posted October 11, 2010 Author Report Share Posted October 11, 2010 Nu vienkārši custom query() funkciju, kas ir uzlabota mysql_query, pēc saviem uzskatiem. un nevis OOP, bet funkcionālās programmēšanas stilā. vai kā to sauc. Quote Link to comment Share on other sites More sharing options...
briedis Posted October 11, 2010 Report Share Posted October 11, 2010 Un kam tev to vajag? :) Ko gribi iegūt? Quote Link to comment Share on other sites More sharing options...
rATRIJS Posted October 11, 2010 Report Share Posted October 11, 2010 function query($q) { $awesominizer = array('awesome', 'innovative', 'superb', 'magical', 'splendid'); echo $awesominizer[array_rand($awesominizer)]; return mysql_query($q); } Pēc maniem uzskatiem uzlabota query funkcija. Dara tieši to pašu ko mysql_query + izvada superīgu tekstu, kas veicina produktivitāti. Quote Link to comment Share on other sites More sharing options...
101111 Posted October 11, 2010 Report Share Posted October 11, 2010 Neesu īpaši izglītots, bet man škiet ka funkctionālā programmēšana ir diezgan sarežģīta programmēšanas paradigma, kurai es pat nezinu pielietojumus. Iespējams proceduālo programmēšanas paradigmu biji domājis. Quote Link to comment Share on other sites More sharing options...
marrtins Posted October 11, 2010 Report Share Posted October 11, 2010 (edited) Kas tur sarežģīts? Ja 10 gadu kodē procedurālā veidā, tad gan ir vajadzīgs laiks, kamēr tiek sev pāri. waplet, kāpēc neder OOP? Un kā atšifrējas FP? Funkcionālā programmēšana, ja? Edited October 11, 2010 by marrtins Quote Link to comment Share on other sites More sharing options...
Леший Posted October 12, 2010 Report Share Posted October 12, 2010 function my_super_query($query){ return #mssql_query($query); #kaut_kaads_tur_veel_query($query); mysql_query($query); } Citu pielietojumu custom query funkcijai procedurālā programmēšanā es neredzu. Quote Link to comment Share on other sites More sharing options...
Klez Posted October 12, 2010 Report Share Posted October 12, 2010 es vēl redzu sitādu variantu: function db_q($q) { return mysql_query($q) or die(mysql_error()); } Vienīgais labums, ko saskatu šajā, tad var mainīt or die daļu. respektīvi var izķert kļūdu un rādīt/nerādīt kļūdu. Un ja kaut ko grib pamainīt, tad nav jāmaina visās vietās. Quote Link to comment Share on other sites More sharing options...
codez Posted October 12, 2010 Report Share Posted October 12, 2010 Var sakabināt klāt automātisku parametru eskeipošanu, aptuveni tā: function q($query){ function esc(&$arr){ foreach($arr as &$el){ if (is_string($el)){ $el = "'".mysql_real_escape_string($el)."'"; } elseif (is_array($el)){ esc($el); $el=implode(',',$el); } } } $args=func_get_args(); array_shift($args); print_r($args); esc($args); print_r($args); $query=vsprintf($query, $args); $res=mysql_query($query) or die(mysql_error().' '.$query); return $res; } izmanto aptuveni tā: $res=q('SELECT * FROM users WHERE'); $res=q('SELECT * FROM users WHERE un=%s and psw=%s',$un,$psw); $res=q('SELECT * FROM users WHERE un IN (%s)',array('john','bill')); Quote Link to comment Share on other sites More sharing options...
waplet Posted October 12, 2010 Author Report Share Posted October 12, 2010 Nu jā, codez, jau laikam saprata , ko biju domāji.. un jā Proceduālā tomēr (tmi) Nu es biju domājis tādu, kas atgriež datus, pēc tā, kas ir saņemts. Quote Link to comment Share on other sites More sharing options...
krikulis Posted October 12, 2010 Report Share Posted October 12, 2010 (edited) Brīvā improvizācija par tēmu /** Izpilda vaicaajumu un pie katras rindas izpilda callback. Man naff ne jausmas kaa php kaut ko asinhroni izpildiit, taadeelj risinaajums principaa ir bezjeedziigs, tiiri pirkstu virinaashanai. principaa izmanto globaalo mysql linku, kas ir patizli, bet man ir lauziens rakstiit visu mysql wrapperi funkcionaali, kas savukaart dotu shaadaas taadas priekshrociibas. Principaa uzskatu, PHP prieksh FP sachko. Demonstree teoreetiski shaadads funkcionaalaas programeeshas iespeejas: closures, anoniimaas funkcijas :) Taa kaa man naff php uz datora un ir lauziens instaleet, tad kods naff notesteets. (php kauchkur jaavelk, jaakompileee, etc... ). lauziens. Laidiisies tikai uz 5.3++ izmantoshanas piemeers vareetu buut shaads: super_q("SELECT * FROM TABLE", function ($data) { echo "<tr>"; $row = function($item){ echo "<td>" . htmlspecialchars($item) . "</td>"; } array_walk($row, $data); echo "</tr>"; }, function (){ echo "<table>"; }, function (){ echo "</table>"; }, function ($error, $number){ ECHO "EPIC FAIL($error)[$number]"; }); */ function super_q($query, $onData, $onStart = NULL, $onEnd = NULL, $onFail = NULL){ $result = mysql_query($query); if ($onFail){ $fail = function() { $onFail(mysql_error(), mysql_errno()); } } else { $fail = function() { } } if ($onStart){ $start = function () { $onStart(); } } else { $start = function () { } } if ($onEnd){ $end = function () { $onEnd(); } } else { $end = function() { } } if $result === false { $fail; } $started = false; $walk_mysql = function (){ while($row = mysql_fetch_assoc($result)){ $onData($row); } } $start(); $walk_mysql(); $end(); } es gan taisiitu OOP variantaa, as tad var ieimplementeet interfeisus itereeshanai etc, kas paveertu shaadas smukas iespeejas... <?php foreach(new Query("SELECT * FROM TABLE") as $row){ var_dump($row); } if (count(Query("SELECT count(*) FROM table")) > 0){ echo "YO"; } ?> Edited October 12, 2010 by krikulis Quote Link to comment Share on other sites More sharing options...
mefisto Posted October 12, 2010 Report Share Posted October 12, 2010 ... šeit laikam neviens par PDO dzirdējis nav .. Quote Link to comment Share on other sites More sharing options...
krikulis Posted October 13, 2010 Report Share Posted October 13, 2010 Dooh ... īsti veči lieto ancient tizlas funkcijas, kam raksta tikpat tizlus wrapperus ... :-> p.s. PDO galīgi nav funkcionālas developēšanas paradigmai piemērots <O> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.