marechy Posted June 20, 2003 Report Share Posted June 20, 2003 Esmu uztaisiijis piemeeru no php graamatas "Soli pa solim", bet kaut kas neshtopee kaa vajag. Eku uztaisiiju taalaak redzamo php skriptu, bet vinjhs kaut ko negrib saglabaat infu datu baazee par katru lietotaaju kas gaajis, mosh ziniet kas par probleemu? <code><font color="#000000"> <font color="#0000CC"><? </font><font color="#006600">function </font><font color="#0000CC">db_conn</font><font color="#006600">(</font><font color="#0000CC">$q</font><font color="#006600">){ </font><font color="#0000CC">$dbh</font><font color="#006600">=@</font><font color="#0000CC">[url=http://lv.php.net/mysql_connect]mysql_connect[/url]</font><font color="#006600">(</font><font color="#CC0000">"localhost"</font><font color="#006600">,</font><font color="#CC0000">"root"</font><font color="#006600">); @</font><font color="#0000CC">[url=http://lv.php.net/mysql_select_db]mysql_select_db[/url]</font><font color="#006600">(</font><font color="#CC0000">"test"</font><font color="#006600">); </font><font color="#0000CC">$res</font><font color="#006600">=@</font><font color="#0000CC">[url=http://lv.php.net/mysql_query]mysql_query[/url]</font><font color="#006600">(</font><font color="#0000CC">$q</font><font color="#006600">); </font><font color="#0000CC">$row</font><font color="#006600">=@</font><font color="#0000CC">[url=http://lv.php.net/mysql_fetch_array]mysql_fetch_array[/url]</font><font color="#006600">(</font><font color="#0000CC">$res</font><font color="#006600">); </font><font color="#0000CC">$val</font><font color="#006600">=</font><font color="#0000CC">$row</font><font color="#006600">[</font><font color="#0000CC">0</font><font color="#006600">]; </font><font color="#0000CC">$dbc</font><font color="#006600">=array(</font><font color="#0000CC">$dbh</font><font color="#006600">,</font><font color="#0000CC">$res</font><font color="#006600">,</font><font color="#0000CC">$val</font><font color="#006600">); return </font><font color="#0000CC">$dbc</font><font color="#006600">; } function </font><font color="#0000CC">clean_up</font><font color="#006600">(</font><font color="#0000CC">$dbh</font><font color="#006600">,</font><font color="#0000CC">$res</font><font color="#006600">){ @</font><font color="#0000CC">[url=http://lv.php.net/mysql_free_result]mysql_free_result[/url]</font><font color="#006600">(</font><font color="#0000CC">$res</font><font color="#006600">); @</font><font color="#0000CC">[url=http://lv.php.net/mysql_close]mysql_close[/url]</font><font color="#006600">(</font><font color="#0000CC">$dbh</font><font color="#006600">); } function </font><font color="#0000CC">print_counter</font><font color="#006600">(</font><font color="#0000CC">$p</font><font color="#006600">){ </font><font color="#0000CC">$ts</font><font color="#006600">=</font><font color="#0000CC">[url=http://lv.php.net/time]time[/url]</font><font color="#006600">() - </font><font color="#0000CC">$p</font><font color="#006600">*</font><font color="#0000CC">86400</font><font color="#006600">; </font><font color="#0000CC">$q</font><font color="#006600">=</font><font color="#CC0000">"select count(distinct host) from stats where ts >= $ts"</font><font color="#006600">; </font><font color="#0000CC">$dbc</font><font color="#006600">=</font><font color="#0000CC">db_conn</font><font color="#006600">(</font><font color="#0000CC">$q</font><font color="#006600">); </font><font color="#0000CC">$hosts</font><font color="#006600">=</font><font color="#0000CC">$dbc</font><font color="#006600">[</font><font color="#0000CC">2</font><font color="#006600">]; </font><font color="#0000CC">clean_up</font><font color="#006600">(</font><font color="#0000CC">$dbc</font><font color="#006600">[</font><font color="#0000CC">0</font><font color="#006600">],</font><font color="#0000CC">$dbc</font><font color="#006600">[</font><font color="#0000CC">1</font><font color="#006600">]); </font><font color="#0000CC">$q</font><font color="#006600">=</font><font color="#CC0000">"select count(*) from stats where ts >= $ts"</font><font color="#006600">; </font><font color="#0000CC">$dbc</font><font color="#006600">=</font><font color="#0000CC">db_conn</font><font color="#006600">(</font><font color="#0000CC">$q</font><font color="#006600">); </font><font color="#0000CC">$hits</font><font color="#006600">=</font><font color="#0000CC">$dbc</font><font color="#006600">[</font><font color="#0000CC">2</font><font color="#006600">]; </font><font color="#0000CC">clean_up</font><font color="#006600">(</font><font color="#0000CC">$dbc</font><font color="#006600">[</font><font color="#0000CC">0</font><font color="#006600">],</font><font color="#0000CC">$dbc</font><font color="#006600">[</font><font color="#0000CC">1</font><font color="#006600">]); </font><font color="#0000CC">$q</font><font color="#006600">=</font><font color="#CC0000">"select count(*) from stats"</font><font color="#006600">; </font><font color="#0000CC">$dbc </font><font color="#006600">=</font><font color="#0000CC">db_conn</font><font color="#006600">(</font><font color="#0000CC">$q</font><font color="#006600">); </font><font color="#0000CC">$total</font><font color="#006600">=</font><font color="#0000CC">$dbc</font><font color="#006600">[</font><font color="#0000CC">2</font><font color="#006600">]; </font><font color="#0000CC">clean_up</font><font color="#006600">(</font><font color="#0000CC">$dbc</font><font color="#006600">[</font><font color="#0000CC">0</font><font color="#006600">],</font><font color="#0000CC">$dbc</font><font color="#006600">[</font><font color="#0000CC">1</font><font color="#006600">]); print (</font><font color="#CC0000">"</font><font color="#006600">[</font><font color="#CC0000">adreses: <b>$hosts</b></font><font color="#006600">]</font><font color="#CC0000"> </font><font color="#006600">[</font><font color="#CC0000">apmeklējumi: <b>$hits</b></font><font color="#006600">]</font><font color="#CC0000"> </font><font color="#006600">[</font><font color="#CC0000">pavisam: <b>$total</b></font><font color="#006600">]</font><font color="#CC0000">"</font><font color="#006600">); } </font><font color="#0000CC">$host</font><font color="#006600">=</font><font color="#0000CC">[url=http://lv.php.net/gethostbyaddr]gethostbyaddr[/url]</font><font color="#006600">(</font><font color="#0000CC">$_server</font><font color="#006600">[</font><font color="#CC0000">"remote_addr"</font><font color="#006600">]); </font><font color="#0000CC">$ref</font><font color="#006600">=</font><font color="#0000CC">$_server</font><font color="#006600">[</font><font color="#CC0000">"http_referer"</font><font color="#006600">]; </font><font color="#0000CC">$req</font><font color="#006600">=</font><font color="#0000CC">$_server</font><font color="#006600">[</font><font color="#CC0000">"request_uri"</font><font color="#006600">]; </font><font color="#0000CC">$agent</font><font color="#006600">=</font><font color="#0000CC">$_server</font><font color="#006600">[</font><font color="#CC0000">"http_user_agent"</font><font color="#006600">]; </font><font color="#0000CC">$tmp</font><font color="#006600">=</font><font color="#0000CC">[url=http://lv.php.net/explode]explode[/url]</font><font color="#006600">(</font><font color="#CC0000">";"</font><font color="#006600">,</font><font color="#0000CC">$agent</font><font color="#006600">); </font><font color="#0000CC">$browser</font><font color="#006600">=</font><font color="#0000CC">$tmp</font><font color="#006600">[</font><font color="#0000CC">1</font><font color="#006600">]; </font><font color="#0000CC">$os</font><font color="#006600">=</font><font color="#0000CC">[url=http://lv.php.net/str_replace]str_replace[/url]</font><font color="#006600">(</font><font color="#CC0000">")"</font><font color="#006600">,</font><font color="#CC0000">""</font><font color="#006600">,</font><font color="#0000CC">$tmp</font><font color="#006600">[</font><font color="#0000CC">2</font><font color="#006600">]); </font><font color="#0000CC">$ts</font><font color="#006600">=</font><font color="#0000CC">[url=http://lv.php.net/time]time[/url]</font><font color="#006600">(); </font><font color="#0000CC">$q</font><font color="#006600">=</font><font color="#CC0000">"insert into stats values(NULL,'$host','$browser','$os','$ts','$req','$ref')"</font><font color="#006600">; </font><font color="#0000CC">$dbc </font><font color="#006600">=</font><font color="#0000CC">db_conn</font><font color="#006600">(</font><font color="#0000CC">$q</font><font color="#006600">); </font><font color="#0000CC">clean_up</font><font color="#006600">(</font><font color="#0000CC">$dbc</font><font color="#006600">[</font><font color="#0000CC">0</font><font color="#006600">],</font><font color="#0000CC">$dbc</font><font color="#006600">[</font><font color="#0000CC">1</font><font color="#006600">]); </font><font color="#0000CC">?> </font> </font> </code> Link to comment Share on other sites More sharing options...
v3rb0 Posted June 20, 2003 Report Share Posted June 20, 2003 1. Noņem nost "@" simbolus pirms mysql_connect, mysql_select_db un mysql_query . Tad tev vajadzētu redzēt kaut kādus kļūdas paziņojumus. 2. Saliec aiz katras mysql_* funkcijas echo mysql_error(); Tādejādi tu dabūsi "cilvēcīgus" kļūdas paziņojumus. Tur varētu būt problēmas ar to, ka nevar pieslēgties pie datubāzes vai ka nav tāda tabula, vai tabulai nav kāds lauks. Link to comment Share on other sites More sharing options...
Benvenuto Posted June 21, 2003 Report Share Posted June 21, 2003 Man bija liidziiga probleema, kuru atrisinaaju ljoti prasti - paarinstaleeju php. aniivei sourcee neesmu tavaa iedziljinaajies, vari meegjinaat paarinstaleet, sliktaak nebuus ;) Link to comment Share on other sites More sharing options...
Recommended Posts