phpbar.de logo

Mailinglisten-Archive

[php] Drei Arten, Daten aus einer Datenbank zu holen

[php] Drei Arten, Daten aus einer Datenbank zu holen

Martin Paff php_(at)_phpcenter.de
Thu, 2 Aug 2001 12:48:31 +0200


Hi an alle,

ich bin etwas verwirrt. Ingesamt habe ich drei Arten gefunden, die =
gleichen
Daten aus einer Datenbank zu holen. Kann mir einer erkl=E4ren, warum =
das so
ist, welchen Unterschied das jeweils macht und welches der beste Weg =
ist?

F=FCr mich scheint Variante B der beste zu sein, da man am wenigsten =
Code
schreiben mu=DF.

Zur Erl=E4uterung habe ich einmal ein paar Zeilen geschrieben, um das =
zu
illustrieren. Ich glaube, das beispiel ist selbsterkl=E4rend.=20

Danke!
Martin

//
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D
=3D
include("test_db.inc");

$sql =3D "SELECT datum, wert FROM nz_stats=20
			WHERE datum >=3D '2001-07-01'=20
			AND datum <=3D '2001-07-31'
			AND rubrik =3D 'sum'
			";

//
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D
=3D
// Variante A
if ($variante =3D=3D "A")
{
	$dbhandler =3D mysql_connect($site, $username, $password);
	mysql_select_db($dbname, $dbhandler);
	$result =3D mysql_query($sql);
	while ($zeile =3D mysql_fetch_array($result))
	{
		$datum =3D $zeile["datum"];
		$wert =3D $zeile["wert"];
		echo "<BR>$datum: $wert";
	}
}

//
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D
=3D
// Variante B
if ($variante =3D=3D "B")
{
	$result =3D mysql($dbname, $sql);
	while ($myrow =3D mysql_fetch_row($result))=20
	{
		echo "<BR>$myrow[0]: $myrow[1]";
	}
}

//
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=
=3D=3D=3D=3D
=3D
// Variante C
if ($variante =3D=3D "C")
{
	# News selektieren
	$result =3D mysql($dbname, $sql);
	$num =3D mysql_numrows($result);
	$i =3D 0;
	while ($i<$num):
		$datum =3D mysql_result($result,$i,"datum");
		$wert =3D mysql_result($result,$i,"wert");
		echo "<BR>$datum: $wert";
		$i++;
	endwhile;
}



php::bar PHP Wiki   -   Listenarchive