Script PHP untuk export Query MySQl ke Excel

ini script mencetak script php dengan database mysql ke  Ms.Excel

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

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<mysql_num_fields($q); $i++) {
$res .= $r[$i] . “\t”;
$res .= “\r\n”;
header(“Content-disposition: attachment; filename=aan.xls”);
header(“Content-type: Application/exe”);
header(“Content-Transfer-Encoding: binary”);
echo $res;

script ini untuk melakukan koneksi dengan database my sql
$hostname = “localhost”; // deklarasikan host komputer anda
$username = “root”; // deklarasikan user database
$database = “___”;    // deklarasikan nama databasenya disini
$password = “”;  // deklarasikan user database
$conn = mysql_connect($hostname,$username,$password);

script mencetak php ke ms excel
header(“Content-disposition: attachment; filename=____.xls”); // diisi nama file ms.excel
header(“Content-type: Application/exe”);
header(“Content-Transfer-Encoding: binary”);

link asal

Categories: PHP | Leave a comment

Post navigation

Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s

Blog at

%d bloggers like this: