Log in

View Full Version : Help with Karma -> Reputation PHP Script Please


addict
10-25-2005, 03:53 AM
Well, the header pretty much says it all.

We've been using vBulletin 2.3.7 for the past couple of years, and wish to upgrade to v3.5 within the next couple weeks. It's been my job to prepare for the conversion, and I need a bit of help. We've been using the Karma hack for vb 2.x, and when upgrading I'd like to transfer this all over to the new vb reputation system.

The script I've written works, but exits after about half of the records have been transferred (there's 36,931 total records in Karma, and only 17,987 in Reputation when it times out).

Anyway, here's the code I'm using... forgive my kludgy code... this is the first time I've even attempted to write any PHP/MySQL code.

<?php
$dbhost = 'localhost';
$dbuser = 'root';
$dbpass = '<password>';

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

$dbname = 'forums';
mysql_select_db($dbname);

$query = "SELECT karmaid, postid, userid, whoadded, karmapos, karmaneg, reason, timestamp FROM karma";
$result = mysql_query($query);

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

mysql_select_db($dbname);
$postid = $row['postid'];
$userid = $row['userid'];
$reputation = ($row['karmapos'] - $row['karmaneg']);
$whoadded = $row['whoadded'];
$reason = $row['reason'];
$dateline = $row['timestamp'];
$query2 = "INSERT INTO reputation (postid, userid, reputation, whoadded, reason, dateline) VALUES ('$postid', '$userid', '$reputation', '$whoadded', '$reason', '$dateline')".
mysql_query($query2) or die ('Error with this insert');

}


mysql_close($conn);
?>


I get this error in the httpd.log when I run this script: PHP Notice: Undefined variable: query2 in /Users/david/Sites/karma.php on line 27, but the script still seems to run okay.

What I'd like to know is if there is something I'm doing wrong that is causing the script to end before it's supposed to?

I checked over my PHP (4.3.11) settings, and set_time_limit is set at 30 seconds, and PHP's memory is set at 8MB. Do I need to set any of these to a different value? I tried to do it via a php.ini file, but it didn't seem to make a difference (the values are still the same).

I'd appreciate any help I could get... I hate it when I'm almost there, yet have some little problem that keeps me from getting across that final step.

Thanks.