Jump to content

Transfer Data From mdb to mysql


googlexx

Recommended Posts

so im trying to transfer data from an mdb to a mysql database using php and im having some trouble:

 

this is what my mdb looks like

 

table name = Users

|----------------------------

| Username    | Experience  |

|----------------------------

| bob            |  600          |

| tyler            | 700            |

| joe              | 300            |

-----------------------------

 

and this is my mysql database:

 

table name = scores

|----------------------------

| Username    | Experience  |

|----------------------------

| bob            |  900          |

| joe              | 200            |

-----------------------------

 

im trying to update it if it exists and insert a new row for the person if it doesnt exist except its not working....

 

here is my code:

 

<?php
$dbhost = 'localhost';
$dbuser = 'xxx';
$dbpass = 'xxx';
$dbname = 'xxx';

//mysql
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);

//mdb
$conn2 = new COM("ADODB.Connection") or die("Cannot start ADO"); 
// Microsoft Access connection string.
$conn2->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=C:\Program Files\folder\database.mdb");
$rs = $conn2->Execute("SELECT Username, Experience FROM Users");


while (!$rs->EOF) 
				{
				$experience = $rs->Fields("Experience");
				$username_old = $rs->Fields("Username");
				$username = strtolower($username_old);

				$sql = "SELECT `username` FROM scores WHERE `username`='$username' ";
				$result = mysql_query($sql) or die(mysql_error());

					if (mysql_num_rows($result) )
					{
						mysql_query("UPDATE scores SET Experience = '$experience' WHERE username = '$username'"); 

					}
					else
					{
						$query = "INSERT INTO scores (Username, Experience) VALUES ('$username', '$experience')";
						$result = mysql_query($query) or die(mysql_error());
   
					}
   
				$rs->MoveNext();
				}

   mysql_free_result($result);
    $rs->Close();
    $conn2->Close();
    $rs = null;
    $conn2 = null;
    
   
     
?>

Link to comment
https://forums.phpfreaks.com/topic/163067-transfer-data-from-mdb-to-mysql/
Share on other sites

oops forgot to include the error:

when i run the page all i get is this and its not changing the db:

 

Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=C:\Program Files\folder\database.mdb"); $rs = $conn2->Execute("SELECT Username, Experience FROM Users"); while (!$rs->EOF) { $experience = $rs->Fields("Experience"); $username_old = $rs->Fields("Username"); $username = strtolower($username_old); $sql = "SELECT `username` FROM scores WHERE `username`='$username' "; $result = mysql_query($sql) or die(mysql_error()); if (mysql_num_rows($result) ) { mysql_query("UPDATE scores SET Experience = '$experience' WHERE username = '$username'"); } else { $query = "INSERT INTO scores (Username, Experience) VALUES ('$username', '$experience')"; $result = mysql_query($query) or die(mysql_error()); } $rs->MoveNext(); } mysql_free_result($result); $rs->Close(); $conn2->Close(); $rs = null; $conn2 = null; ?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.