PHP的MySQL阵列 - 插入阵列信息到mysql [英] php mysql array - insert array info into mysql

查看:85
本文介绍了PHP的MySQL阵列 - 插入阵列信息到mysql的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在字段中插入多发数据,然后将其恢复为数组。
 例如,我需要插入99999进表item_details,现场 ITEM_NUMBER ,并以下数据字段投标人相关与 ITEM_NUMBER
  userx
  usery
  userz
 可否请您让我知道我应该用什么SQL查询来插入信息,哪些查询,检索呢?
 我知道这可能是一个愚蠢的问题,但我只是无法弄清楚。

I need to insert mutiple data in the field and then to retrieve it as an array. For example I need to insert "99999" into table item_details , field item_number, and the following data into field bidders associated with item_number : userx usery userz Can you please let me know what sql query should I use to insert the info and what query to retrieve it ? I know that this may be a silly question but I just can't figure it out .

感谢你在前进,
迈克尔。

thank you in advance, Michael .

推荐答案

如果你只是想在一个MySQL字段存储数组供以后检索,那么你可以使用破灭() [ PHP文档]作为上述建议(这会破坏数组的键,但保留了阵列的价值观),或连载() [ PHP文档]将保留双方的价值观和相关联的密钥。

If you are simply wanting to store an array in a MySQL Field for later retrieval, then you could use implode()[PHP Docs] as suggested above (which will destroy the array's keys, but retain the array's values), or serialize()[PHP Docs] which will retain both the values and the associated keys.

$theArray = array(
  'key1' => 'One' ,
  'key2' => 'Two'
);
$serArray = serialize( $theArray ); // a:2:{s:4:"key1";s:3:"One";s:4:"key2";s:3:"Two";}
$sqlStr = 'INSERT INTO `table` ( `name` , `arrayField` ) VALUES ( "Test Row" , "'.$serArray.'" )';

如果你谈论的是使用两个相关的表来存储数据,那么你可能最好请参考与教程一样的 http://www.sql-tutorial.net/SQL-JOIN.asp ,<一个href=\"http://www.databasejournal.com/features/oracle/article.php/3527921/Just-SQL-Part-IV--Joining-Tables.htm\" rel=\"nofollow\">http://www.databasejournal.com/features/oracle/article.php/3527921/Just-SQL-Part-IV--Joining-Tables.htm

If you are talking about using two related table to store data, then you are probably best advised to refer to tutorials like http://www.sql-tutorial.net/SQL-JOIN.asp, http://www.databasejournal.com/features/oracle/article.php/3527921/Just-SQL-Part-IV--Joining-Tables.htm

这篇关于PHP的MySQL阵列 - 插入阵列信息到mysql的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆