In PHP you can connect to all sort of database, you just need to enable the right directive in the ini file, the most common is PHP+MySQL or MSSQL.
In my case I choose to use MySQL because it is open source and its free.
Connect to database server
$conn = mysql_connect("[DB IP address]", "[DB server username]", "[DB server password]");
DB IP address usually is localhost if the DB is install in the same IP machine.
For example
$conn = mysql_connect("localhost", "dbAdmin", "12345678");
if(!$conn){
die('Could not connect to:'.mysql_error());
}
or
$conn = @mysql_connect('localhost', 'dbAdmin', '12345678') or die(mysql_error());
To select a DB to use
$db = mysql_select_db("DatabaseName", $conn);
To setup a SQL Statement
$sqlString = 'SELECT * FROM tbl_user';
or sql statement can be change by getting value from a form
$strValue = $_POST['table'];
$sqlString = 'SELECT * FROM '.$strValue;
Get the result from the SQL statement and put it into a result set
$rs = mysql_query($sqlString);
Loop through each row using while loop and display using table
echo('<table width="50%" border="1px" cellpadding=0 cellspacing=0>');
echo("<tr><th>UserID</th><th>First Name</th><th>Last Name</th><th>User Name</th><th>Password</th></tr>");
while($i < mysql_num_rows($rs)){
$row = mysql_fetch_array($rs, MYSQL_ASSOC);
echo('<tr>');
foreach($row as $val){
echo('<td>');
echo($val);
echo('</td>');
}
echo('</tr>');
$i++;
}
<table style="width: 50%;" border="1px" cellspacing="0" cellpadding="0">
<tbody>
<tr>
<th>UserID</th>
<th>First Name</th>
<th>Last Name</th>
<th>User Name</th>
<th>Password</th>
</tr>
<tr>
<td>'); echo($val); echo('</td>
</tr>
</tbody>
</table>
<pre><code>
");
or you can choose which field to display
echo('<table width="50%" border="1px" cellpadding=0 cellspacing=0>');
echo("<tr><th>User Name</td><th>Password</td></tr>");
while($row = mysql_fetch_array($rs)){
echo ('<tr><td>'.$row['username'].'</td>');
echo ('<td>'.$row['password'].'</td></tr>');
}
echo("</table>");
And then finally, you need to close the connection
mysql_close($conn);