Home |
Search |
Today's Posts |
#1
Posted to microsoft.public.excel.programming
|
|||
|
|||
New to accessing mysql dbase in excel vba
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é+ |
Reply |
Thread Tools | Search this Thread |
Display Modes | |
|
|
Similar Threads | ||||
Thread | Forum | |||
Should/Can Excel be used as a dbase | Excel Discussion (Misc queries) | |||
Best way to export from Excel to MySQL? | Excel Discussion (Misc queries) | |||
Import MySQL data to Excel | Excel Discussion (Misc queries) | |||
MySQL and excel | Excel Discussion (Misc queries) | |||
Excel and Dbase | Excel Programming |