Jump to content
php.lv forumi

Vmysql Class


Recommended Posts

Manupraat logjiski ir rakstiit kaut kadu unikalaaku klasi t.i. ar supportu vairaakaam db (pgsql, ms sql, oracle)

jo diezvai ir jedzigi izmantot mysql_connect vietaa piemeeram db_con()..

Link to post
Share on other sites

Man bija slinkums kaut ko ielaadeet un skatiities, bet db_conn() lietoshana mysql_connect() vietaa tiek saukta par abstrakciju un pie citas db vienkarshi tiks uzrakstiita sav db_conn() f-ja.

 

<code><font color="#000000">
<font color="#0000CC"><?php
</font><font color="#006600">class </font><font color="#0000CC">AbstractDatabase
</font><font color="#006600">{
</font><font color="#0000CC">metodes</font><font color="#006600">, </font><font color="#0000CC">kas kopīgas visām DB
</font><font color="#006600">}
</font><font color="#0000CC">?></font>
</font>
</code>

 

failaa mysql.php piemeram:

 

<code><font color="#000000">
<font color="#0000CC"><?php
</font><font color="#006600">class </font><font color="#0000CC">Database </font><font color="#006600">extends </font><font color="#0000CC">AbstractDatabase
</font><font color="#006600">{
</font><font color="#0000CC">metodes</font><font color="#006600">, </font><font color="#0000CC">kas raksturiigas tikai MySQL db
db_conn</font><font color="#006600">() </font><font color="#0000CC">prieksh MySQL</font><font color="#006600">, </font><font color="#0000CC">db_query</font><font color="#006600">() </font><font color="#0000CC">prieksh MySQL </font><font color="#006600">...
}
</font><font color="#0000CC">?></font>
</font>
</code>

failaa postgresql.php:

<code><font color="#000000">
<font color="#0000CC"><?php
</font><font color="#006600">class </font><font color="#0000CC">Database </font><font color="#006600">extends </font><font color="#0000CC">AbstractDatabase
</font><font color="#006600">{
</font><font color="#0000CC">metodes</font><font color="#006600">, </font><font color="#0000CC">kas raksturiigas tikai PostgreSQL db
db_conn</font><font color="#006600">() </font><font color="#0000CC">prieksh PostgreSQL</font><font color="#006600">, </font><font color="#0000CC">db_query</font><font color="#006600">() </font><font color="#0000CC">prieksh PostgreSQL </font><font color="#006600">...}
}
</font><font color="#0000CC">?></font>
</font>
</code>

 

<code><font color="#000000">
<font color="#0000CC"><?php
$dbtype </font><font color="#006600">= </font><font color="#CC0000">'postgresql'</font><font color="#006600">;
include(</font><font color="#0000CC">$dbtype</font><font color="#006600">.</font><font color="#CC0000">'.php'</font><font color="#006600">);
</font><font color="#0000CC">$db </font><font color="#006600">= new </font><font color="#0000CC">Db</font><font color="#006600">();
...
</font><font color="#0000CC">$result </font><font color="#006600">= </font><font color="#0000CC">$db</font><font color="#006600">-></font><font color="#0000CC">db_query</font><font color="#006600">(</font><font color="#CC0000">"SELECT ME"</font><font color="#006600">);
...
if (</font><font color="#0000CC">$numrows </font><font color="#006600">= </font><font color="#0000CC">$db</font><font color="#006600">-></font><font color="#0000CC">getNumRows</font><font color="#006600">(</font><font color="#0000CC">$result</font><font color="#006600">)) ...
</font><font color="#0000CC">?></font>
</font>
</code>

Link to post
Share on other sites
  • 3 months later...
Manupraat logjiski ir rakstiit kaut kadu unikalaaku klasi t.i. ar supportu vairaakaam db (pgsql, ms sql, oracle)

jo diezvai ir jedzigi izmantot mysql_connect vietaa piemeeram db_con()..

arii taadas jau ir dabunamas gatavas - taa ka nav jeegas divriteni no jauna izgudrot ;) . es piemeeram izmandoju <a href="http://php.weblogs.com/ADOdb">ADODB</a>. IMHO ljoti laba klase

Link to post
Share on other sites
arii taadas jau ir dabunamas gatavas - taa ka nav jeegas divriteni no jauna izgudrot ;) . es piemeeram izmandoju <a href="http://php.weblogs.com/ADOdb">ADODB</a>. IMHO ljoti laba klase

Es neteicu ka taadas nav pieejamas (nosauc kaut 3 lietas kas nav jau reiz uzrakstiitas vai kaut kur nepiedaavaajas ieksh php), tas bija mans komentaars attieciibaa tieshi uz sho klasi un ideju kopumaa..

Link to post
Share on other sites
×
×
  • Create New...