Saving for tag "$tag_html"\n"; $dsn = "mysqli://$user:$passwd@$host/$db"; $conn =& DB::connect($dsn); if (DB::isError($conn)) { die ("Cannot connect: " . $conn->getMessage() . "\n"); } $conn->query("SET NAMES utf8"); $insert = $conn->prepare('INSERT INTO tagcomments SET tag=?, comment=?, score=0'); $result = $conn->execute($insert, array($tag, $comment)); if (DB::isError($result)) { die ("INSERT failed: " . $result->getMessage() . "\n"); } $id = 0; $getid = $conn->prepare('SELECT MAX(id) FROM tagcomments WHERE tag=? AND comment=? AND score=0'); $result = $conn->execute($getid, array($tag, $comment)); if (DB::isError($result) || $result->numRows() != 1) { die ("GET ID failed: " . $result->getMessage() . "\n"); } else { $row =& $result->fetchRow(); $id = $row[0]; } if($id == 0) { die ("GET ID failed: got id 0"); } else { echo "Comment saved as id $id
"; } $commentLenZ = strlen(gzcompress($comment)); $newscore = 0; $getother =& $conn->prepare("SELECT id, comment, score FROM tagcomments WHERE tag=?"); $result = $conn->execute($getother, $tag); if (DB::isError($result)) { die ("SELECT failed: " . $result->getMessage() . "\n"); } while($row =& $result->fetchRow()) { $otherLenZ = strlen(gzcompress($row[1])); $sum = strlen(gzcompress($comment.$row[1])); $sim = ($commentLenZ + $otherLenZ) / $sum; $otherid = $row[0]; $score = $row[2]; //echo "id = $otherid, score = $score, similarity = $sim
\n"; if($score * ($sim - 1) > $newscore) { $newscore = $score * ($sim - 1); } } $result->free(); $newscore = (int)$newscore; $updatescore =& $conn->prepare("UPDATE tagcomments SET score=? WHERE id=?"); $result =& $conn->execute($updatescore, array($newscore, $id)); if (DB::isError($result)) { die ("UPDATE score failed: " . $result->getMessage() . "\n"); } else { echo "You post was granted an initial score of $newscore

\n"; } $conn->disconnect(); echo "Rare values\n"; echo "Popular values\n"; echo "Back to index page\n"; ?>