Access转mysql(wordpress 转库)

来源:互联网 发布:vmware桥接网络设置 编辑:程序博客网 时间:2024/05/01 15:47
博客改版,需要从access数据库把文章转入mysql数据库。代码贴出:
<?phptry{    //getcwd过去当前路径    $db = new PDO("odbc:driver={microsoft access driver (*.mdb)};dbq=".getcwd()."\\#tot_news.mdb");    echo "Access Connected\r\n";} catch (Exception $e) {    echo "Failed:".$e->getMessage();}  //选择数据库表  $rs=$db->query("select * from xinwentg");  $dbh = new PDO('mysql:host=localhost;dbname=wordpress','root','root');   $dbh->query('set names gb2312;');  while($row=$rs->fetch()){    //标题    $title=$row[title];    //内容    $contxt=$row[content];    $content=addslashes($contxt);    //iconv('gb2312', 'utf-8', $content);    //时间    $time=$row[riqi];    $url="http://www.baidu.com";    /*    ID:自增唯一ID    post_author:对应作者ID    post_date:发布时间    post_date_gmt:发布时间(GMT+0时间)    post_content:正文    post_title:标题    post_excerpt:摘录    post_status:文章状态(publish/auto-draft/inherit等)    comment_status:评论状态(open/closed)    ping_status:PING状态(open/closed)    post_password:文章密码    post_name:文章缩略名    to_ping:未知    pinged:已经PING过的链接    post_modified:修改时间    post_modified_gmt:修改时间(GMT+0时间)    post_content_filtered:未知    post_parent:父文章,主要用于PAGE    guid:未知    menu_order:排序ID    post_type:文章类型(post/page等)    post_mime_type:MIME类型    comment_count:评论总数    */    $sql="    INSERT INTO `wp_posts`(`post_author`,`post_date`,    `post_date_gmt`, `post_content`, `post_title`,    `post_status`, `comment_status`,`ping_status`,    `post_name`,`post_modified`, `post_modified_gmt`,    `post_parent`, `guid`,`menu_order`,`post_type`,    `comment_count`,`post_excerpt` ,`to_ping`,    `pinged`,`post_content_filtered`)VALUE    ('1','".$time."','".$time."','".$content."','".$title."','publish','open','open','','".$time."','".$time."','0','.".$url."',    '0','post','0','','','','');";    $dbh->query($sql);    $id=$dbh->lastInsertId();    echo "The".$id."success\r\n";    /*    object_id:对应文章ID/链接ID    term_taxonomy_id:对应分类方法ID    term_order:排序    */    $sql2="INSERT INTO`wp_term_relationships` ( `object_id`, `term_taxonomy_id`, `term_order`)VALUE ( '".$id."', '16',  '0')";    $dbh->query($sql2);    echo "The".$id."条success\r\n";   };?>