New to accessing mysql dbase in excel vba

A

affordsol

Hi everyone !

I've never done it before, but I need to get some data out of a mysql
database.
I'm still using Excel97 SR-2.

The following php script does exactly what I want to do : My question is :
how can I do it with a VBA Sub ???
<?php
// Here we tell the browser that this is an excel file.
header("Content-type: application/octet-stream");
header("Content-Disposition: attachment; filename=testing.xls");
header("Pragma: no-cache");
header("Expires: 0");

$user = "username"; //MySQL Username
$password = "userpassword"; // MySQL Username's Password
$dbname= "databasename"; //Database Name
$tablename ="tablename"; // DB Table Name

// localhost is the default database hosf for most servers, you might need
to change yours if it doesnt work
$global_dbh = mysql_connect("mysqlserver", $user, $password); // This
establishes the database connection

mysql_select_db($dbname, $global_dbh); // Select what database to use

// You do not need to change the function
function display_db_table($tablename, $connection)
{
$query_string = "select * from $tablename";
$result_id = mysql_query($query_string, $connection);
$column_count = mysql_num_fields($result_id);

while ($row = mysql_fetch_row($result_id))
{
for ($column_num = 0;$column_num < $column_count; $column_num++)
{
echo "$row[$column_num]\t";
}
echo "\n";
}
}

display_db_table($tablename, $global_dbh);
// You can have multiple tables in one excel spreadsheet, just copy the
line to the left and change the table name.
?>


Thanks a lot for your help and regards from Belgium,
Hervé+
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

export MySQL to Excel? 7

Top