我有一个正在编写的脚本,用于将某些字段移至新的数据库,例如
$results = mysql_query ( "SELECT body, title FROM $source_db.Post" ); while ($row = mysql_fetch_array($results)) { if(mysql_num_rows($users_result) > 0){ $insert = "INSERT INTO wp_posts (`body`,`title`) VALUES ('{$row['body']}', '{$row['row']}')"; mysql_query($insert); } }
但是如您所见,由于单引号和双引号,查询每次都会中断,是否有解决此问题的方法,例如herdok或类似的东西
INSERT INTO wp_posts (`body`,`title`) VALUES ('Here are the final returns from today's ...<br /><br />he stayed home...<br /> <div class="entry-content"> <div class="entry-body">', 'something')
mysql_real_escape_string 为此而制作的。
mysql_real_escape_string
PHP:mysql_real_escape_string
$insert = "INSERT INTO wp_posts ('body','title') VALUES ('".mysql_real_escape_string($row['body'])."', '".mysql_real_escape_string($row['row'])."')";