Script PHP untuk export Query MySQl ke Excel

<form id=”form1″ name=”form1″ method=”post” action=”excel.php”>
<p>
QUERY : <br />
<textarea name=”sql” cols=”50″ rows=”6″ id=”sql”></textarea>
</p>
<p>
<input type=”submit” name=”Submit” value=”Submit” />
</p>
</form>
<p style=”text-align: justify;”><strong>Nama File : excel.php</strong>
<?php
$hostname = “localhost”;
$username = “root”;
$database = “a”;
$password = “”;
$conn = mysql_connect($hostname,$username,$password);
mysql_select_db($database);

if (isset($_POST[‘sql’]))
{
$q = mysql_query(stripslashes($_POST[‘sql’])) or die (“Not valid query !”);
$res = “”;
while ($f = mysql_fetch_field($q)) {
$res .= $f->name . “t”;
}
$res .= “rn”;
while ($r = mysql_fetch_array($q)) {
for ($i=0; $i<mysql_num_fields($q); $i++) {
$res .= $r[$i] . “t”;
}
$res .= “rn”;
}
mysql_free_result($q);
header(“Content-disposition: attachment; filename=aan.xls”);
header(“Content-type: Application/exe”);
header(“Content-Transfer-Encoding: binary”);
echo $res;
}
?>

Comments are closed.

Scroll to top
error: Salam TIF-UAD