douwo6738 2015-06-29 13:13
浏览 125
已采纳

MYSQL,PHP:将记录从一个数据库插入另一个数据库

I have a necessity to insert some record from one table1 in database1 to another table2 in database2. So far I have this..

    $records_r = mysqli_fetch_assoc(mysqli_query($conn_r, "SELECT * FROM `export` WHERE ID < 100"));        

    $columns_r = implode(",",array_keys($records_r));
    $values_r = implode(",",array_values($records_r));          

    $import = mysqli_query($conn_i,"INSERT INTO NOTimport ($columns_r) values ($values_r)");
    if (!$import) {
    printf("Error: %s
", mysqli_error($conn_i));
    exit();}

It gives me the error:

Error: You have an error in your SQL syntax;

This is how the syntax looks:

INSERT INTO `NOTimport` ('xx,xx,xx,xx,xx,xx,xx,xx') values ('11,'11,E,2079,1931,xx,xx,x')

I am 99% sure that single quotes are causing the error, but why are there?

  • 写回答

3条回答 默认 最新

  • duanba8173 2015-06-29 13:55
    关注

    Without Using PHP you can use MySql Query Which Will Perform Insert Operation As:-

    $columns_r='`name`,`class`';
    
    mysqli_query($conn_i,"INSERT INTO `import` ({$columns_r}) select {$columns_r} from `export`");
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(2条)

报告相同问题?

悬赏问题

  • ¥20 腾讯企业邮箱邮件可以恢复么
  • ¥15 有人知道怎么将自己的迁移策略布到edgecloudsim上使用吗?
  • ¥15 错误 LNK2001 无法解析的外部符号
  • ¥50 安装pyaudiokits失败
  • ¥15 计组这些题应该咋做呀
  • ¥60 更换迈创SOL6M4AE卡的时候,驱动要重新装才能使用,怎么解决?
  • ¥15 让node服务器有自动加载文件的功能
  • ¥15 jmeter脚本回放有的是对的有的是错的
  • ¥15 r语言蛋白组学相关问题
  • ¥15 Python时间序列如何拟合疏系数模型