Jump to content

Convert .mdb to mysql


googlexx

Recommended Posts

So i wrote this script to add a .mdb database to a mysql database but im getting a parse error on line 29... Any ideas?

 

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

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
$conn2 = new COM("ADODB.Connection") or die("Cannot start ADO"); 

mysql_select_db($dbname);
$sql = "SELECT username, money FROM forumuser";
$result = mysql_query($sql);

// Microsoft Access connection string.
$conn2->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=C:\Documents and Settings\Brown\Desktop\Trivia\plugins\ST_users.mdb");
$rs = $conn2->Execute("SELECT Money, Username");
while (!$rs->EOF) 
    {
$score = $rs->Fields("Money");
$username = $rs->Fields("Username");

        while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) 
        {
         $username2=$row["username"];
         $score2=$row["money"];

	    if ($username == $username2) {
		$dbquery = "INSERT INTO $score2 VALUES ('$score')"
            $dbresult = mysql_query ($dbquery, $conn);
	    }

	}

    $rs->MoveNext();
    } 
mysql_free_result($result);
    $rs->Close(); 
   
     
?>

Link to comment
Share on other sites

ok that fixed the error but its not update the table: and on the echo part its reading all the values correctly.

 

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

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
$conn2 = new COM("ADODB.Connection") or die("Cannot start ADO"); 
mysql_select_db($dbname);

$sql = "SELECT username, money FROM forumuser";
$result = mysql_query($sql);

// Microsoft Access connection string.
$conn2->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=C:\Documents and Settings\Brown\Desktop\Trivia\plugins\ST_users.mdb");
$rs = $conn2->Execute("SELECT Money, Username FROM users");
while (!$rs->EOF) 
    {
$score = $rs->Fields("Money");
$username = $rs->Fields("Username");

        while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) 
        {

         $username2=$row["username"];
         $score2=$row["money"];

	    if ($username == $username2) {
		mysql_query("UPDATE users SET $score2 = '$username' WHERE $username2 = '$score'");

		echo "Importing money from trivia: ".$score." from name: ".$username." to: ".$username2." old score: ".$score2; 
	    }

	}

    $rs->MoveNext();
    } 
mysql_free_result($result);
    $rs->Close(); 
   
     
?>

Link to comment
Share on other sites

alright, i've managed to get it working except i have one little error... it only updates the first line or the .mdb file....

 

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

$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
$conn2 = new COM("ADODB.Connection") or die("Cannot start ADO"); 
mysql_select_db($dbname);

$sql = "SELECT username, money FROM forumuser";
$result = mysql_query($sql);

// Microsoft Access connection string.
$conn2->Open("DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=C:\Documents and Settings\Brown\Desktop\Trivia\plugins\ST_users.mdb");
$rs = $conn2->Execute("SELECT Money, Username FROM users");


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

            while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) 
            {
             $username2_old=$row["username"];
             $score2=$row["money"];
	     $username2 = strtolower($username2_old);

			if ($username == $username2) 
			{
			mysql_query("UPDATE forumuser SET money = '$score' WHERE '$username2' = '$username'");
			echo "Importing money from trivia: ".$score." from name: ".$username." to: ".$username2." old score: ".$score2; 
			}

	    }
		$rs->MoveNext();
    } 
mysql_free_result($result);
    $rs->Close(); 
   
     
?>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.