By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,678 Members | 1,904 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,678 IT Pros & Developers. It's quick & easy.

database conversion

P: n/a
Ok. So I am in the middle of a switch from an asp message board, snitz
to be exact, to pbpbb. So far I have not all the members, forums, and
categories converted. But the toll I found made by a nifty person
named Raluca Musaloiu-E. is not working for the topics. I think this
is because there is too many special characters in the body of the
posts to the board.

Here is the error I am getting. And bellow that is the converter that
Raluca Musaloiu-E made. Any suggestions of things I can try to the
converter work? It is only converting about 7 posts out of 4,000.
*****************************Error**************** *********************

Start index:
5 7 8 9 12 13 14 15 16 MySQL error on query BR> INSERT INTO
phpbb_posts_text VALUES ( '16', '', NULL, 'cool. what should i bring?
unfortunately, all my cards are mostly jyhad backed. I have a few
sabbat and some dark sovereigns. that\'s really about it though :-\');
mysql_errno = 1064
mysql_error = You have an error in your SQL syntax near ''cool. what
should i bring? unfortunately, all my cards are mostly jyhad backed.'
at line 5

*****************************Converter************ *********************

<?php
require("config.php");
?>

<html>

<head>
<title>Snitz 2 phpBB2 Convertor - Posts</title>
<p>

<?php
$strQueryError = "MySQL error on query";

// display the mysql error that occurs during execution of query $q
function query_error($q)
{
global $strQueryError;
echo $strQueryError." BR>\n";
echo $q."<BR>\n";
echo "mysql_errno = ".mysql_errno()."<BR>\n";
echo "mysql_error = ".mysql_error()."<BR>\n";
die;
}

function encode_ip($dotquad_ip)
{
$ip_sep = explode('.', $dotquad_ip);
return sprintf('%02x%02x%02x%02x', $ip_sep[0], $ip_sep[1],
$ip_sep[2], $ip_sep[3]);
}

$link1 = mysql_connect($server1, $user1, $password1);
$link2 = mysql_connect($server2, $user2, $password2);

// get a valid start index

$query = mysql_db_query($db2, "SELECT post_id FROM $phpbb_posts ORDER
BY post_id DESC;", $link2);
$row = mysql_fetch_array($query);
$idx = $row[post_id];
echo "Start index: $idx<br>";

$query = mysql_db_query($db1, "SELECT * FROM $forum_reply ORDER BY
REPLY_ID ASC;", $link1);
$i = 0;
$debug1 = 0;
$debug2 = 0;

while($row = mysql_fetch_array($query)) {
$idx++;

$year1 = substr($row[R_DATE], 0, 4);
$month1 = substr($row[R_DATE], 4, 2);
$day1 = substr($row[R_DATE], 6, 2);
$hour1 = substr($row[R_DATE], 8, 2);
$min1 = substr($row[R_DATE], 10, 2);
$sec1 = substr($row[R_DATE], 12, 2);
$date1 = mktime($hour1, $min1, $sec1, $month1, $day1, $year1);

// $message = strip_tags(str_replace("'", "\\'", $row[R_MESSAGE]));
$message = str_replace("'", "\\'", $row[R_MESSAGE]);
$ip = encode_ip($row[R_IP]);
echo "$row[REPLY_ID] ";

// for one post i have to do 2 inserts: into posts and into posts_text

$q1 = "INSERT INTO $phpbb_posts VALUES (
'$row[REPLY_ID]',
'$row[TOPIC_ID]',
'$row[FORUM_ID]',
'$row[R_AUTHOR]',
$date1,
'$ip',
NULL,
'1',
'0',
'1',
'0',
NULL,
'0');";

if (mysql_db_query($db2, $q1, $link2) or query_error($q1))
$debug1++;
else
echo "$debug1 - Error2<br>";

$q2 = "INSERT INTO $phpbb_posts_text VALUES (
'$row[REPLY_ID]',
'',
NULL,
'$message');";

if (mysql_db_query($db2, $q2, $link2) or query_error($q2))
$debug2++;
else
echo "$debug2 - Error3<br>";
}
echo "DONE"
?>

</body>
</html>
Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Nekosama wrote:
MySQL error on query BR> INSERT INTO
phpbb_posts_text VALUES ( '16', '', NULL, 'cool. what should i bring?
unfortunately, all my cards are mostly jyhad backed. I have a few
sabbat and some dark sovereigns. that\'s really about it though :-\');


Escape that backslash in the fellow's emoticon.

In fact, you should escape a number of special characters. There was a
thread on this subject on this mailing list earlier this week.

Since you are using PHP, check this out:
http://ca2.php.net/mysql_escape_string

Regards,
Bill K.
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.