Script PHP untuk export Query MySQl ke Excel





QUERY :






Nama File : excel.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 .= “\r\n”;
while ($r = mysql_fetch_array($q)) {
for ($i=0; $i
$res .= $r[$i] . “\t”;
}
$res .= “\r\n”;
}
mysql_free_result($q);
header(“Content-disposition: attachment; filename=aan.xls”);
header(“Content-type: Application/exe”);
header(“Content-Transfer-Encoding: binary”);
echo $res;
}
?>

0 comments:

Post a Comment