WeberDev.com PHP and MySQL Code

LOG IN
BEGINNER GUIDES  |  PHP CLASSES  |  CODE SEARCH  |  ARTICLES SEARCH  |  PHP FORUMS  |  PHP MANUAL  |  PHP FUNCTIONS LIST  |  WEB SITE TEMPLATES
Start typing to search for PHP and MySQL Code Snippets and Articles Search
Submit a code Example / Snippet Submit Your Code
Search Engine Optimization Monitor SEO Monitor
Web Site UpTime Monitor UpTime Monitor
WeberDev's Monthly code contest PHP Code Contest
Your Personal Examples List My Favorite Examples
Your Personal Articles List My Favorite Articles
Edit Account Info Update Your Profile
PHP Code Search
Web Development Forums
Learn MySQL Playing Trivia
PHPBB2 Templates
Web Development Index
Web Development Resources
Web Development Content
PHPClasses
PHP Editor
PHP Jobs
Vision.To Design
Ajax Tutorials
PHP Programming Help
PHP/MySQL Programming
Webmaster Resources
Webmaster Forum
XML meta language
website builder
Mobile Dev World

Go Back Add a Comment Send this example to a friend Add this Article to your personal favoritest for easy future access to your favorite Code Examples and Articles. Submit a code example Print this code example.
BACK ADD A COMMENT SEND TO A FRIEND ADD TO MY FAVORITES ADD CODE EXAMPLES PRINT
Title : This program allows you to upload an ODBC ressource - i.e. an MS-Access database to a MySQL server.
Categories : Databases, MySQL, Complete Programs, PHP, Databases Update Picture
Soren Roug
Date : Jan 17th 1999
Grade : 2 of 5 (graded 4 times)
Viewed : 18939
File : No file for this code example.
Images : No Images for this code example.
Search : More code by Soren Roug
Action : Grade This Code Example
Tools : My Examples List

  Submit your own code examples 
 

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
BBS system for easy customization. Utilizes mySQL.
Categories : Complete Programs, MySQL, PHP, 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
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
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
Example voting script. Lets people enter suggestions and vote for existing ones.
Categories : MySQL, PHP, Cookies, Complete Programs, Databases
Tropicalm Genetree Family (MySQL based family tree)
Categories : PHP, Interfaces, Databases, MySQL, Complete Programs
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
phpMyAdmin is intended to handle the adminstration of MySQL over the web.
Categories : Databases, MySQL, Complete Programs, PHP
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
This program will take data from a user via a web based form, validate it, show it to the user for re-validation, and finally insert it into the database. Plenty of sanity checking on the fields in the form.
Categories : MySQL, HTML and PHP, PHP, Complete Programs, Databases
 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..?