ViaThinkSoft CodeLib
This article is in:
CodeLib → Programming aids → PHP
<?php
$db_server = '...';
$db_username = '...';
$db_password = '...';
$db_database = '...';
$link = mysql_connect($db_server, $db_username, $db_password);
if (!$link)
{
die('Keine Verbindung möglich: '.mysql_error());
}
$db_selected = mysql_select_db($db_database, $link);
if (!$db_selected)
{
die('Datenbank "'.$db_database.'" kann nicht geöffnet werden: '.mysql_error());
}
$res = mysql_query("...");
if ($res)
{
echo 'Elemente: '.mysql_num_rows($res)."\n";
while ($row = mysql_fetch_array($res))
{
echo $row['feldname']."\n";
}
// Alternativ
// while ($row = mysql_fetch_object($res))
// {
// echo $row->feldname;
// echo "\n";
// }
}
else
{
echo 'MySQL-Abfrage ist fehlgeschlagen: '.mysql_error();
}
mysql_close($link);
?>
Daniel Marschall
ViaThinkSoft Co-Founder
ViaThinkSoft Co-Founder