<html>
<head>
<title>Retrieve column info from database</title>
<style>
a {text-decoration:none}
table {font-family:arial; font-size:11pt}
</style>
</head>
<body bgcolor=lightyellow>
<h1><center>Retrieve column info from database</center></h1>
<h2>The "student" table column info</h2>
<?php
$host = 'localhost'; #local (either PC or NYU server)
display();
//===============================================================================
function display()
{
global $host;
$host_port = $host;
$DBname = 'demo';
$DBuser = 'demo';
$DBpswd = 'demo';
$connect = mysqli_connect($host_port,$DBuser,$DBpswd,$DBname); #connect to db server
if (! $connect)
die('Could not connect: ' . mysqli_connect_error());
$query = "select * from student as stu";
$cursor = mysqli_query($connect,$query); #execute the query
if (! $cursor)
die('Could not execute query: ' . mysqli_error($connect));
print "<table bgcolor=#eeeeee border=5 width=800 outset>
<tr bgcolor=tan>
<th>Table Name<th>Column Name<th>Table Alias<th>Column Alias<th>Type<th>Length
<th>Decimal<th>Default Value<th>Character Set<th>Flags \n";
while ($field = mysqli_fetch_field($cursor))
{
print "<tr>";
print "
<td> $field->orgtable
<td> $field->orgname
<td> $field->table
<td> $field->name
<td> $field->type
<td> $field->max_length
<td> $field->decimals
<td> $field->def
<td> $field->charsetnr
<td> $field->flags
";
print "</tr>";
}
print "</table>";
mysqli_free_result($cursor); #free result buffer
mysqli_close($connect); #close connection
}
//===============================================================================
?>
<?php include "../include.php"; ?> <!-- hyperlink to see the code -->
</body>
</html>