topical media & game development
server-php-db-xml-index.php / php
<?php
error_reporting(0);
// Function to write html header information only for display form and XML
// In case of saving file we don't need this code
function writeHeader(){
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Database To XML</title>
<link href="style/style.css" rel="stylesheet" type="text/css" />
</head>
<body>';
}
// Check whether one of the submit button was pressed
if (isset(_POST['dispBtn'])){
// Set the variables from the user input
_POST['hostname'])? user = isset(_POST['username'] : '';
_POST['password'])? port = isset(_POST['port'] : '3306';
outfile= '';
host.":".link = mysql_connect(user,link){
echo '<div id="main"><div id="formheader">Can not connect to database: '.mysql_error().' </div></div>';
die;
}
// Get all databases
outfile.='<MySQLserver hostname="'.user.'" password="'.port.'">'."\n";
host.'" username="'.pass.'" port="'.dbrow = mysql_fetch_array(db = db,result = mysql_query('SHOW TABLES');
db'>\n";
out.=htmlspecialchars("<Database name='row = mysql_fetch_array(table = struct = mysql_query('DESCRIBE '.outfile.=' <Table name="'.out.=" ";
table.'">'."\n");
// Get all fields for the actual table
while (struct, MYSQL_NUM)) {
row2[5],'auto_increment')) ? 'YES' : 'NO';
row2[0].'" ';
row2[1].'" ';
row2[2].'" ';
row2[3].'" ';
row2[4].'" ';
autoi.'"/>'."\n";
tmp;
out.=htmlspecialchars(outfile.=' </Table>'."\n";
out.=htmlspecialchars('</Table>'."\n");
}
// Close database element
out.=" ";
outfile.='</MySQLserver>';
_POST['dispBtn'])){
writeHeader();
echo '<div id="main2"><div id="formbody2">';
echo nl2br(filecontent=downloadfile='MySQL_Server.xml';
header("HTTP/1.1 200 OK");
header("Content-Length: ".strlen(downloadfile");
header("Content-Transfer-Encoding: binary");
echo _SERVER['PHP_SELF']; ?>" method="post" name="dbXml" id="dbXml">
<table align="center">
<tr><th>Hostname:</th><td><input name="hostname" type="text" size="30" maxlength="15" value="localhost"></td></tr>
<tr><th>Username:</th><td><input name="username" type="text" size="30" maxlength="15"></td></tr>
<tr><th>Password:</th><td><input name="password" type="password" size="30" maxlength="15"></td></tr>
<tr><th>Port:</th><td><input name="port" type="text" size="30" value="3306"></td></tr>
<tr>
<td align="center"><br/><input class="text" type="submit" name="saveBtn" value="Save as..."></td>
<td align="center"><br/><input class="text" type="submit" name="dispBtn" value="Display output"></td>
</tr>
</table>
</form>
</div>
</div>
</body>
<?php
}
?>
(C) Æliens
20/2/2008
You may not copy or print any of this material without explicit permission of the author or the publisher.
In case of other copyright issues, contact the author.