Trac3 !! Posted September 3, 2009 Report Share Posted September 3, 2009 (edited) Sveiki. Vēlos, lai jūs novērtējat, palabojat šo mysql klasi, gaidu ari ieteikumus, ko uzlabot, pielikt klāt vai atnemt nost :) Links uz klases kodu.. http://paste.php.lv/c2d23691ef207838132e68e189b81b3d?lang=php Uzlabotā versija: http://paste.php.lv/fa459bd4fef70eb6b381ac373eac9c0d?lang=php Upgrade 2: http://paste.php.lv/9cb55f79745bdddf0c6ff381c055c6ac?lang=php Daži piemēriņi kā lietot klasi. //mysql savienojuma izveide include("../secure/classes/mysql.class.php"); $sql = new MySQL("elisits", "elisitsparole", "elisits"); $sql->query("INSERT INTO users VALUES('', 'Trac3', 'parole')"); $sql->query("INSERT INTO users VALUES('', %s, %s)", "lietotajs", "parole"); $sql->query("INSERT INTO users VALUES('', 'Trac3 otrais', 'parole')"); $sql->query("INSERT INTO users VALUES('', %s, %s)", "lietotajs otrais", "parole"); $data = $sql->getResult("SELECT * FROM users"); for($i=0;$i<count($data);$i++){ echo $data[$i]->UID." - ".$data[$i]->name." - ".$data[$i]->pass."<br />"; } echo $sql->getVar("SELECT name FROM users WHERE UID=2")."<br />"; $sql->query("SELECT * FROM users WHERE UID < 3"); $data2 = $sql->getResult(); for($i=0;$i<count($data2);$i++){ echo $data2[$i]->UID." - ".$data2[$i]->name." - ".$data2[$i]->pass."<br />"; } $data3 = $sql->getRow(); echo $data3->UID." - ".$data3->name." - ".$data3->pass."<br />"; $data3 = $sql->getRow(false, 1); // x un y skaitishana no nulles :) echo $data3->UID." - ".$data3->name." - ".$data3->pass."<br />"; echo $sql->getVar()."<br />"; echo $sql->getVar(false, 2, 1)."<br />"; $sql->query("SELECT * FROM hkfadjs"); //neeksistejosha tabula lai apskatitos kludas pazinojumu :) echo $sql->getError(); Edited September 5, 2009 by Trac3 !! Quote Link to comment Share on other sites More sharing options...
EdgarsK Posted September 3, 2009 Report Share Posted September 3, 2009 Loti labi ! Tiešām pozitīva atsauksme no manas puses ! Diezgan ērta lietošana. Quote Link to comment Share on other sites More sharing options...
bubu Posted September 3, 2009 Report Share Posted September 3, 2009 return call_user_func_array('sprintf', $arr) vietā var lietot vsprintf funkciju. Tad nevajadzēs lietot call_user_func_array. Quote Link to comment Share on other sites More sharing options...
Kemito Posted September 3, 2009 Report Share Posted September 3, 2009 Diezgan pozitīvi, pat no mana skatījuma! Quote Link to comment Share on other sites More sharing options...
marrtins Posted September 3, 2009 Report Share Posted September 3, 2009 LastId() pietrūkst :) Quote Link to comment Share on other sites More sharing options...
EdgarsK Posted September 3, 2009 Report Share Posted September 3, 2009 marrtins ko tu ar to biji domajis ? jaa piekriitu bubu par vsprint Quote Link to comment Share on other sites More sharing options...
Trac3 !! Posted September 3, 2009 Author Report Share Posted September 3, 2009 nezinaju par vsprinf funkciju, noeikti izlaboshu ;) ko tu domā ar LastId(), ko man vajadzētu atgriest ar viņu? Quote Link to comment Share on other sites More sharing options...
werd Posted September 3, 2009 Report Share Posted September 3, 2009 mysql_insert_id(); Quote Link to comment Share on other sites More sharing options...
Trac3 !! Posted September 3, 2009 Author Report Share Posted September 3, 2009 Šī funkcija man bijusi nepieciešama ļoti reti, tāpēc es pats viņu nelikšu iekšām, bet ja vēlies priekš sevis var ielikt, kas to bieži izmanto :) Pielaboju arī nedaudz pāsu klasi, jaunais source ir atrodams te: http://paste.php.lv/fa459bd4fef70eb6b381ac373eac9c0d?lang=php Quote Link to comment Share on other sites More sharing options...
krikulis Posted September 3, 2009 Report Share Posted September 3, 2009 Ar ko klase ir labāka par PDO / MYSQLi ? Quote Link to comment Share on other sites More sharing options...
ziemelis Posted September 3, 2009 Report Share Posted September 3, 2009 (edited) labs darbs, varu papildus ieteikt funkciju kura reize veic query un reize nosaka affected rows function queryz($query, $err=1){//echo "<br><span class=red>".$query."</span>"; $r = mysql_query ($query); if(!$r) if($err==0){echo($this->error($query, mysql_error()));}elseif($err==1){die($this->error($query, mysql_error()));} $this->$sqlasijumi++; $r=mysql_affected_rows();return ($r>0)?$r:false; } pielietojums: $rez = $sql_db->queryz("UPDATE ".KOM_TABLE." SET uid = '".$sql_db->esc($id2)."',zid = '".$sql_db->esc($id3)."',msg='".$sql_db->esc($id4)."' WHERE ID ='".$sql_db->esc($id1)."'"); if($rez){ // } vel var noderet kludu logosana failaa Edited September 3, 2009 by ziemelis Quote Link to comment Share on other sites More sharing options...
marcis Posted September 3, 2009 Report Share Posted September 3, 2009 (edited) $i = 0; while($row = @mysql_fetch_object($this->query)){ $this->result[$i] = $row; $i++; } No mainīgā $i varētu vispār atbrīvoties... P.S. trigger_error() Edited September 3, 2009 by marcis Quote Link to comment Share on other sites More sharing options...
codez Posted September 4, 2009 Report Share Posted September 4, 2009 Kāpēc gan labāk DB klasi netaisīt kā singletona paternu, kurš ekstendo standarta mysqli klasi un pielikt dažas funkcijas automātiskai eskeipošanai un izmantot autoload funkciju klases ielādei. Labumi no tā ir tādi, ka nav jāuztraucas par includes likšanu, nav jāuztraucas par klases instances izveidošanu un piekonektēšanos DB. Piemēram, izmantojot šādu klasi, es jebkurā vietā varu rakstīt šādi, un veiksmīgi tiks izsaukt kverijs - bez includēm un konekciju rakstīšanām: Protams, tas viss ir MVC freimworka ietvaros. LDb::i()->q('SELECT ....'); LDb::i() - izsauc klases funkciju statiski, kura pārbauda vai ir jau instance izveidota, ja nav tad izveido, piekonektējas un atgriež klases instanci. Quote Link to comment Share on other sites More sharing options...
krikulis Posted September 5, 2009 Report Share Posted September 5, 2009 (edited) DB konekciju nevajag likt kā singleton freimworka kontekstā - ir diezgan daudz scenāriji, kur jāslēdzas dažādām DB / ar dažādiem lietotājiem. P.S. par funkciju nosaukumu ar vienu zīmi un obscured klašu nosaukumu veidošanu vajadzētu nocirst pirkstus un mūžīgi banot no datora lietošanas. Edited September 5, 2009 by krikulis 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.