This program allows you to upload an ODBC ressource - i.e. an MS-Access database to a MySQL server. The table must already exist on MySQL It will figure out which fields are defined in the MySQL table and then upload the coresponding field from the ODBC ressource. If you give it no arguments. It will show you a list of tables in the MySQL database.
<?php
/*
* This include file defines the functions html_header and html_footer
*/
require( "design.inc");
$mysqldb = "concord";
function nonfatal_error($message)
{
printf( "<H1>%s</H1>\n",$message);
}
function upload_records($odbcfd,$myfd,$mysqldb,$table)
{
/*
* Figure out which columns the mysql database has
*/
$fieldlist = mysql_list_fields($mysqldb,$table);
$numof = mysql_num_fields($fieldlist);
for($i = 0; $i < $numof; $i++)
{
$fieldname = mysql_field_name($fieldlist,$i);
if($i == 0)
$columnlist = $fieldname;
else
$columnlist = $columnlist . "," . $fieldname;
$fieldtype = mysql_field_type($fieldlist,$i);
switch($fieldtype)
{
case "string":
case "datetime":
$fieldquotes[$fieldname] = "'";
break;
default:
$fieldquotes[$fieldname] = "";
break;
}
}
/*
* Query the ODBC database and loop through the result.
*/
$res = odbc_exec($odbcfd, "SELECT * FROM $table");
if($res == 0)
{
nonfatal_error( "Couldn't exec SELECT statement on ODBC database");
return(0);
}
/*
* Now we know we can query the ODBC database we can delete the records from
the Mysql
* database
*/
mysql_db_query($mysqldb, "DELETE FROM $table",$myfd);