';
$table = 'stops';
// Pose a query. $query is a string. Use the last one of the following queries.
$query = "show databases";
$query = "show tables from $db_name";
$query = "show columns from $table from $db_name";
$query = "select * from $db_name.$table";
// Query the database. $sth is a handle.<
$sth = mysql_query($query);
// Examine the rows of a table. $row is an associative array.
// while ( $row = mysql_fetch_assoc($sth) ) {
// or
// while ( $row = mysql_fetch_array($sth,MYSQL_ASSOC) ) {
while ( $row = mysql_fetch_array($sth,MYSQL_ASSOC) ) {
foreach ($row as $key => $value) {
echo "\$row hat Schlüssel $key mit Wert ".htmlentities($value,ENT_QUOTES,'UTF-8')."
\n";
}
echo "
\n";
// or other form of foreach
foreach ($row as $value) {
echo "\$row hat Wert ".htmlentities($value,ENT_QUOTES,'UTF-8')."
\n";
}
echo "
\n";
}
// Reset pointer in result
mysql_result($sth,0,0);
// Examine the rows of a table. $row is a numerical array.
// while ( $row = mysql_fetch_row($sth) ) {
// or
// while ( $row = mysql_fetch_array($sth,MYSQL_NUM) ) {
while ( $row = mysql_fetch_array($sth,MYSQL_NUM) ) {
for ($i = 0; $i < count($row); $i++) {
echo "\$row hat Index $i mit Wert ".htmlentities($row[$i],ENT_QUOTES,'UTF-8')."
\n";
}
echo "
\n";
}
// Examine the names of the columns of a table.
for ($i = 0; $i < mysql_num_fields($sth); $i++) {
$field_name = mysql_field_name($sth,$i);
echo "'$field_name'
\n";
}
// Free the statement handle.
mysql_free_result($sth);
// Close the database.
mysql_close($dbh);
echo "Weiter?";
?>