Saurdo Posted April 26, 2007 Share Posted April 26, 2007 Hello! I'm attempting to convert my database away from wordpress format. Wordpress just feels too bloated and slows down my site a lot so I'm scrapping it. I'm trying to convert the database with a php script that selects the rows I want from the posts table in the wordpress database and inserts it into another database table in a different database I already made. The problem is that when fetching the current content it seems to convert it so two single quotes next to eachother turns into one and \r\n turns into a new line (when viewing in a text editor). Here's an example. The original database table: (4, 1, '2005-12-19 20:42:39', '2005-12-20 04:42:39', 'Check out this video of me killing some zombies. Eric recorded it and It''s only thirty seconds long. I''m going to be mean and embed it. \r\n\r\n<center><embed SRC="http://atlas.walagata.com/w/saurdo/zombie.wmv" width="320" height="240" loop="false" volume="100%" autostart="false" ></embed>\r\nPress play</center>\r\n\r\nHe added some funky music i provided and I compressed it to one megabyte so it would be painless to download. It''s not very exciting but zombies are cool. I was worried they''d kill Eric because they seemed so attracted to him but I think (as the server admin) i gave him 99999 health. I gave myself something like 500 health and I still almost died. It starts out with me getting annoyed and just shooting a nade at the ground thus sending zombies flying in all directions - that took away 200 of my health.', 'Zombie killing', 0, '', 'publish', 'closed', 'closed', '', 'zombie-killing', '', '', '2006-01-17 15:17:23', '2006-01-17 23:17:23', '', 0, 'http://www.saurdo.com/?p=4', 0, 'post', '', 0), The same code after I try and take out unwanted keys: (4, '2005-12-19 20:42:39', 'Check out this video of me killing some zombies. Eric recorded it and It's only thirty seconds long. I'm going to be mean and embed it. <center><embed SRC="http://atlas.walagata.com/w/saurdo/zombie.wmv" width="320" height="240" loop="false" volume="100%" autostart="false" ></embed> Press play</center> He added some funky music i provided and I compressed it to one megabyte so it would be painless to download. It's not very exciting but zombies are cool. I was worried they'd kill Eric because they seemed so attracted to him but I think (as the server admin) i gave him 99999 health. I gave myself something like 500 health and I still almost died. It starts out with me getting annoyed and just shooting a nade at the ground thus sending zombies flying in all directions - that took away 200 of my health.', 'Zombie killing', '0', 'publish', 'zombie-killing'), Here's my PHP code: <?php $connection = mysql_connect('', '', '') or die('can\'t connect to db'); $db = mysql_select_db('saurdo_blog', $connection) or die('can not select db'); $query = "SELECT * FROM wp_posts ORDER BY ID"; $result = mysql_query($query) or die('Query failed<br>'. mysql_error()); $n=1; while($row = mysql_fetch_array($result)){ $values .= "(".$n.", '".$row['post_date']."', '".$row['post_content']."', '".$row['post_title']."', '".$row['post_category']."', '".$row['post_status']."', '".$row['post_name']."'),"; $n++; } // for debugging //file_put_contents('test.sql', $values); die; $db2 = mysql_select_db('saurdo_site', $connection) or die('can not select db2'); $query2 = "INSERT INTO posts (`ID`, `post_date`, `post_content`, `post_title`, `post_category`, `post_status`, `post_name`) VALUES ".$values; mysql_query($query2) or die('Query2 failed<br>'. mysql_error()); ?> Is there someway I can prevent the conversion? I tried str_replace to redo it but the mysql query still failed for an unknown reason. Link to comment https://forums.phpfreaks.com/topic/48720-converting-database-from-wordpress/ Share on other sites More sharing options...
fert Posted April 26, 2007 Share Posted April 26, 2007 try this $fp=fopen("test.sql","w"); fwrite($fp,$values); fclose($fp); Link to comment https://forums.phpfreaks.com/topic/48720-converting-database-from-wordpress/#findComment-238749 Share on other sites More sharing options...
Saurdo Posted April 26, 2007 Author Share Posted April 26, 2007 I don't think you understood my question, at all. I don't care about writing it to a file, that's just for debugging purposes. I want to rewrite it to another database table but when i fetch the rows they aren't the same as when they're in the database. Link to comment https://forums.phpfreaks.com/topic/48720-converting-database-from-wordpress/#findComment-238764 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.