|
|
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);
$rowinx = 0;
while(odbc_fetch_row($res))
{
/*
* Generate the SQL INSERT STATEMENT
*/
for($i = 0; $i < $numof; $i++)
{
$fieldname = mysql_field_name($fieldlist,$i);
if($i == 0)
$vallist = $fieldquotes[$fieldname] .
addslashes(odbc_result($res,$fieldname)) .
$fieldquotes[$fieldname] ;
else
$vallist = $vallist . "," . $fieldquotes[$fieldname] .
addslashes(odbc_result($res,$fieldname)) .
$fieldquotes[$fieldname] ;
}
$cmd = "INSERT INTO $table ($columnlist) VALUES ($vallist)";
if($rowinx % 10 == 0)
echo "<br>";
printf( "%06s\n",$rowinx);
if(mysql_db_query($mysqldb,$cmd,$myfd) == 0)
{
nonfatal_error(mysql_error());
}
$rowinx++;
}
return(1);
}
/*-----------------------------------------------------------------
* Start of the program
*/
/*
* Connect to the MySQL server
*/
$myfd = mysql_connect( "atilia", "guest", "xxxx");
if($myfd <= 0)
{
nonfatal_error( "Couldn't open MySQL database");
exit($myfd);
}
/*
* Connect to the ODBC ressource.
* The DSN must be defined in the executing computer's ODBC tables
*/
$odbcfd = odbc_connect( "ConcAccess", "x", "e");
if($odbcfd <= 0)
{
nonfatal_error( "Couldn't open ODBC database");
exit($odbcfd);
}
function list_tables($mysqldb)
{
echo "<UL>\n";
$tables= mysql_list_tables($mysqldb);
for($i = 0; $i < mysql_num_rows($tables);$i++)
{
printf( "<LI>Upload table <A HREF=\"upload.php3?table=%s\">%s</A>\n",
mysql_tablename($tables,$i),
mysql_tablename($tables,$i));
}
echo "</UL>\n";
}
switch ($table)
{
case "":
html_header( "Update Database on mysql");
?>
<P>This page allows you to upload tables from the MS-Access database to the
database
on the webserver. There <I>might</I> be some uploading errors. This is the
reason
you can only upload one table at a time. You should select a table and then
look at the
result for errors.</P>
<?php
list_tables($mysqldb);
break;
default:
html_header( "Uploading $table");
echo ( "Row ## Row ## Row ## Row ## Row ## Row ## Row ## Row ## Row ##
Row ##<br>\n");
$tables= mysql_list_tables($mysqldb);
$dotable=0;
for($i = 0; $i < mysql_num_rows($tables); $i++)
if(mysql_tablename($tables,$i) == $table)
{
$dotable=1;
}
if($dotable == 1)
upload_records($odbcfd,$myfd,$mysqldb,$table);
else
nonfatal_error( "There was no such table");
list_tables($mysqldb);
break;
}
odbc_close($odbcfd);
mysql_close($myfd);
html_footer();
?>
|
|
| This is an admin utility to let you manage mysql users from a web page. It works for me.. I've fixed a number of bugs since 1.0, but it's still not very efficient code, and probably still has bugs. Categories : Databases, MySQL, Complete Programs, PHP, Databases | | | bookmarker - PHP, PHPLIB, MySQL WWW based bookmark manager Categories : MySQL, PHP, MySQL, Complete Programs, Databases | | | Simple Mini Poll class library (SimPoll) Categories : PHP, PHP Classes, Databases, MySQL, Complete Programs | | | Shopping Basket On-Line Ordering System. Categories : Complete Programs, MySQL, PHP, Ecommerce, Databases | | | free, search engine, indexing, system, information, web,
ftp, http, free, software, cgi, php, MySQL, database, php3,
FreeBSD, Linux, Unix, UdmSearch Categories : MySQL, Complete Programs, PHP, Databases, Search | | | BBS system for easy customization. Utilizes mySQL. Categories : Complete Programs, MySQL, PHP, Databases | | | complete, simple, working example of a login screen/system using php functions, cookies, and a mysql database for begginers. Categories : Authentication, Complete Programs, PHP, MySQL, Databases | | | Create and restore backup of MySQL databases Categories : MySQL, Databases, PHP, PHP Classes, Complete Programs | | | This is a very simple BBS that uses MySQL Categories : MySQL, Databases, Complete Programs, PHP | | | phpAds, a complete banner and ad management system with detailled tracking and stats. Categories : MySQL, Complete Programs, Ecommerce, PHP, Databases | | | Point and Click Interface ala MS Access for creating SQL statements. Categories : MySQL, Complete Programs, General SQL, PHP, Databases | | | Tropicalm Genetree Family (MySQL based family tree) Categories : PHP, Interfaces, Databases, MySQL, Complete Programs | | | Accepts a database & hostname from a user and then HTTP username and password. Uses this to connect to a MySQL database. Produces a form based on the tables it finds there to allow the user to do SELECTs, INSERTs, and DELETEs. Categories : Databases, PHP, MySQL, Complete Programs | | | Example voting script. Lets people enter suggestions and vote for existing ones. Categories : MySQL, PHP, Cookies, Complete Programs, Databases | | | Education Center is a set of PHP-scripts to administer a corporate education and examination system via Internet/intranet written in PHP for MySQL.
Categories : PHP, Databases, MySQL, Complete Programs | |
| |
| | | | | Terry Ashley wrote :797
Just a quick question would this work for an Excel database as well? If so which variables would you change to determine what cells define what rows in your db..?
| |
|
|