SQL: converting databases

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

SQL: converting databases

Post by psychotomus »

I'm trying to convert some database which I can set in the proper format but some of the text had SQL operators in it.

Code: Select all

INSERT INTO `t_media` 
VALUES ( 334, 'game', 'WhoopAss: Office Edition', 'WhoopAss-Office-Edition, '
CHANGE angle
AND power
TO catapult obstacles at employees before they reach the water cooler. ', '', '', 'gst_1.SWF ', '', 'gst_1.png ', 1, '2007 -02 -1302 :29 :09 ', 0, 0, 0, 0, 'WhoopAss : Office Edition ', '', '', 'Y ', '', '') INSERT INTO `t_media` VALUES (335, 'game ', 'Brown Cow Curling ', 'Brown - Cow - Curling, 'Play a match of curling against your friend or the computer.', '', '', 'gst_2.SWF', '', 'gst_2.png', 1, '2007-02-13 02:29:09', 0, 0, 0, 0, 'Brown Cow Curling', '', '', 'Y', '', '' )

my code to create the dump

Code: Select all

$result = mysql_query( "SELECT * FROM games" )or die("SELECT Error: ".mysql_error());
$counter = 334;
while($row=mysql_fetch_array($result) )
{
	$title = $row['gametitle'];
	$url = str_replace(" ", "-",str_replace(":","",$row['gametitle']));
	$desc = $row['gamedesc'];
	$file = $row['gamefile'];
	$thumb = $row['gameicon'];
	$tags = $row['gamekeywords'];
	if (strpos($file, ".DCR") == false)
	{
		echo  "INSERT INTO `t_media` VALUES ($counter, 'game', '$title', '$url, '$desc', '', '', '$file', '', '$thumb', 1, '2007-02-13 02:29:09', 0, 0, 0, 0, '$tags', '', '', 'Y', '', '')<br>";

		$counter = $counter + 1;
	}
}
User avatar
Mordred
DevNet Resident
Posts: 1579
Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria

Post by Mordred »

mysql_real_escape_string on all variables in the second query.
Are you sure about "$counter", why don't you use auto_increment.
Post Reply