googlexx Posted June 1, 2009 Share Posted June 1, 2009 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 https://forums.phpfreaks.com/topic/160443-convert-mdb-to-mysql/ Share on other sites More sharing options...
trq Posted June 1, 2009 Share Posted June 1, 2009 You rmissing a colon from.... $dbquery = "INSERT INTO $score2 VALUES ('$score')" Link to comment https://forums.phpfreaks.com/topic/160443-convert-mdb-to-mysql/#findComment-846727 Share on other sites More sharing options...
googlexx Posted June 1, 2009 Author Share Posted June 1, 2009 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 https://forums.phpfreaks.com/topic/160443-convert-mdb-to-mysql/#findComment-846749 Share on other sites More sharing options...
googlexx Posted June 1, 2009 Author Share Posted June 1, 2009 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 https://forums.phpfreaks.com/topic/160443-convert-mdb-to-mysql/#findComment-847103 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.