doudiza9154 2012-02-14 08:02
浏览 56
已采纳

Mysql将数据从数组插入多个表

enter image description here

 Tags array(11) {
  ["album"] => string(17) "Away From The Sun"
  ["artist"] => string(12) "3 Doors Down"
  ["bitrate"] => int(256000)
  ["title"] => string(16) "Ticket to Heaven"
  ["filename"] => string(23) "04 Ticket To Heaven.mp3"
  ["format"] => string(3) "mp3"
  ["play_time"] => float(207.5950625)
  ["genre"] => string(11) "Alternative"
  ["year"] => string(4) "2002"
  ["track"] => string(1) "4"
  ["art"] => string(21) "Away From The Sun.jpg"
}

I need help with taking the data from this array and populating these tables with the data and maintaining the relationships.
I extract data from these kinds of tables all the time and I build them with known data.
In this case the data is unknowable to me until I parse the id3 tag.
All 3 tables are auto incrementing on 'id'.
I typically work in Zend Framework, so answers in ZF are really helpful but php and sql are almost as good.
I found one question SQL Insert with data from multiple tables that seems to address this issue, but I don't have the sql to understand the answer.
Would a link table help?

P.S. I know the relationship lines in the figure are incorrect.

  • 写回答

1条回答 默认 最新

  • duanchoupo1104 2012-02-14 08:12
    关注

    Since the relationships depend on autoincrement IDs probably the best thing to do is to insert into the artist table and then call $artist_id = mysql_insert_id() to get the new ID number. You can then insert into album and call the same function as $album_id =mysql_insert_id()`. Finally insert your tracks using the IDs you just retrieved.

    You'll be able to ensure you do not have albums without artists or tracks without albums, and you'll need to insert albums and tracks without creating new artists or albums, so this should easily suffice.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大