Current location: Hot Scripts Forums » Programming Languages » PHP » Convert Access to Mysql


Convert Access to Mysql

Reply
  #1 (permalink)  
Old 04-26-05, 07:58 PM
Dr.Jamescook Dr.Jamescook is offline
Newbie Coder
 
Join Date: Apr 2005
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
Convert Access to Mysql

I would like to know if someone will convert this access database to MySQL for me. This is a one time deal.

Thanks

Note: First i got to figure out how to get the file to you.!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 04-26-05, 08:02 PM
creepycridler's Avatar
creepycridler creepycridler is offline
Wannabe Coder
 
Join Date: Feb 2005
Location: Seatac, WA
Posts: 120
Thanks: 0
Thanked 0 Times in 0 Posts
Can't you save a access database to .csv? Then use phpmyadmin to import the .csv to mysql?

If you get the access to .csv, then I can give you code that someone else has given me to import to your database in mysql.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 04-26-05, 08:07 PM
Dr.Jamescook Dr.Jamescook is offline
Newbie Coder
 
Join Date: Apr 2005
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
I got it there. Access>> Excel >> CSV.

Now where's the code??
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 04-26-05, 08:20 PM
creepycridler's Avatar
creepycridler creepycridler is offline
Wannabe Coder
 
Join Date: Feb 2005
Location: Seatac, WA
Posts: 120
Thanks: 0
Thanked 0 Times in 0 Posts
change the "***" to fit your information and the change the database column info to fit yours.

Question's????

I forgot who gave this to me, but whoever you are...thankyou. It saves me alot of time!

PHP Code:



<?php
// Connection String Variables -------------------
$DBhost "***";
$DBuser "***";
$DBpass "***";
$DBName "***";
$table "***";

// Connect to Database and execute query ---------

mysql_connect($DBhost,$DBuser,$DBpass) or die("Unable to connect to database");

@
mysql_select_db("$DBName") or die("Unable to select database $DBName");

/*   DO MYSQL CONNECTION HERE    */

$file '***.csv'//file name here

//we read the CSV file here
$lines file($file);

//now we take each line and explode it then insert to DB
foreach ($lines as $line) {
   
$cols explode(';'$line);
   
mysql_query("INSERT INTO $table (F_name, L_name, S_name, M_name, N_name, street, city, state, zip, country, phone, email, years, participation, notes) VALUES ('$cols[0]', '$cols[1]', '$cols[2]', '$cols[3]', '$cols[4]', '$cols[5]', '$cols[6]', '$cols[7]', '$cols[8]', '$cols[9]', '$cols[10]', '$cols[11]', '$cols[12]', '$cols[13]', '$cols[14]')")or
   die(
mysql_error());
}

echo 
mysql_affected_rows();

?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 04-26-05, 08:40 PM
Dr.Jamescook Dr.Jamescook is offline
Newbie Coder
 
Join Date: Apr 2005
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
OK, I tried. But this don't work because I have all kinds of punctuation in the last three fields.

What do I do now?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 04-26-05, 08:42 PM
creepycridler's Avatar
creepycridler creepycridler is offline
Wannabe Coder
 
Join Date: Feb 2005
Location: Seatac, WA
Posts: 120
Thanks: 0
Thanked 0 Times in 0 Posts
yeah, for some reason it does not like the " ' " and some others. I just went thru and changed them for the time being. Then changed them back when I got into mysql. I am not that experience with all this. Maybe somebody elese can offer a better solution.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #7 (permalink)  
Old 04-26-05, 08:48 PM
Dr.Jamescook Dr.Jamescook is offline
Newbie Coder
 
Join Date: Apr 2005
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
I hope. I don't need the punctuation but try going through the whole bible removing the punctuation!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 04-26-05, 08:59 PM
matiucarr matiucarr is offline
New Member
 
Join Date: Apr 2005
Location: Auckland
Posts: 4
Thanks: 0
Thanked 0 Times in 0 Posts
You could run some kind of "cleanUpForSQL()" function over each line. Convert ' to '' among other things.

$cols = explode(';', (str_replace("'", "''", $line)));
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 04-26-05, 09:10 PM
Dr.Jamescook Dr.Jamescook is offline
Newbie Coder
 
Join Date: Apr 2005
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
This did something but I am not sure what. It worked for a minute and then the browser said done but there was no printout of affected rows. I looked at the table in PHPMyAdmin and it looked like the whole thing was not there and what was there was messed up. Also, I don't think that it could have converted a 40MB database in 1 minute.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #10 (permalink)  
Old 04-26-05, 10:32 PM
Dr.Jamescook Dr.Jamescook is offline
Newbie Coder
 
Join Date: Apr 2005
Posts: 42
Thanks: 0
Thanked 0 Times in 0 Posts
I found out more exactly what is going on. It is trying to cram the whole line into one field rather than separating the line by the commas and putting those into each field. What do we do from here?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Convert SQL Access to MySQL djavet PHP 1 05-07-04 02:40 PM
Access MySQL at another location? mqcarpenter PHP 8 11-21-03 09:28 AM
Is there any way I can link MS Access to a MySql on a remote web server (ISP)? xmxpcom PHP 2 11-12-03 04:33 AM
mysql to access aspuser25 Database 2 09-16-03 12:01 PM
How to convert an Exchel sheet into MySQL DB Ole Nygaard PHP 1 08-27-03 10:10 AM


All times are GMT -5. The time now is 12:12 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.