Jump to content
php.lv forumi

db klase


ezis

Recommended Posts

sveiki!

zinu, ka ir labas jau gaavas db klases. necensos izgudrot divriteni no jauna, bet gan salikt savejo...

velos uztaisit ko vienkarshu, bet galvenais funkcionejoshu..

pagaidam esmu ticis tik taalu:

 class db{
   function db($host, $dbuser, $dbpass, $db)
   {
     $this->dbc = mysql_connect($host, $dbuser, $dbpass) or die(mysql_error());
     $this->sel_db($db);
   }
   function sel_db( $db )
   {
     mysql_select_db($db) or die(mysql_error());
   }
   function query( $query )
   {
     $this->result = mysql_query($query, $this->dbc);
     return $this->result;
   }
   function getRow($query)
   {
     $result = mysql_query($query) or die(mysql_error());
     $this->rowresult = mysql_fetch_array($result);
     return $this->rowresult;
   }
   function RecordCount( $query )
	{
		return @mysql_num_rows ( mysql_query ( $query ) );
	}
 }

 

viss straadaa, bet kad velos izmantot loop piemeram

 

while( $get_info = $db->getRow("SELECT ...") ){
...
}

 

tad man ir "muuziigais loop", tas ir: loops ilgi vislaik atkartojas. :\

ja ir kadas labas idejas ko piesviest, tad labprat tas uzklausisu.

Paldies!

Link to comment
Share on other sites

fetch un get rows vari taisiit kaa atsevishkjas funkcijas.

 

un tas get row driizaak jaaaizvieto ar fetch. katraa gadiijumaa ja taisi ciklu, tad obligaati jaabuut arii return false, lai tev tas cikls beigtos.

 

var arii paartaisiit to klasi ar implements Iterator, lai vareetu pa smuko taisiit kaa apmeeram tu esi iedomaajies.

 

un veel pie fetch_array izmanto veel papildus parametru - MYSQL_ASSOC vai MYSQL_NUM, lai lieku datu apojmu nedzenaatu.

Link to comment
Share on other sites

MYSQL_ASSOC un MYSQL_NUM nezimantoju, jo ir ta4u def vertibas, ka piemeram MYSQL_BOTH utt, laikam.. neesmu drosh.. atziisos, maz ko zinu!

Kaklz, prieksh manim nav apala 0 si klase, klasi izmantot ir nedaudz atrak un pieraksta sanak nedaudz isaks kods..

 

tas ko es taisu, vnk for fun, izmantojot parasti ezSQL, bet gribas nomicit savu klasi.

 

edits: labak ir ari ja, uztiasitu piemeram funkciju eroriem? lai nebutu ta, ka blauj defaultos msql erorus?

Edited by ezis
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...