Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/254.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Codeigniter-从数据库中的嵌套数组插入多个值_Php_Arrays_Codeigniter_Nested - Fatal编程技术网

Php Codeigniter-从数据库中的嵌套数组插入多个值

Php Codeigniter-从数据库中的嵌套数组插入多个值,php,arrays,codeigniter,nested,Php,Arrays,Codeigniter,Nested,Oke,因此正如标题所示,我希望在一个数据库字段中插入嵌套数组中的多个值 需要明确的是,下面的数组将位于数据库中的一条记录中,而不是多行中 这就是我的阵列的外观 array(5) { ["stars"]=> array(5) { [0]=> string(10) "Chris Pine" [1]=> string(14) "Zachary Quinto" [2]=> string(11) "Zoe Saldana"

Oke,因此正如标题所示,我希望在一个数据库字段中插入嵌套数组中的多个值

需要明确的是,下面的数组将位于数据库中的一条记录中,而不是多行中

这就是我的阵列的外观

array(5) {
  ["stars"]=>
  array(5) {
    [0]=>
    string(10) "Chris Pine"
    [1]=>
    string(14) "Zachary Quinto"
    [2]=>
    string(11) "Zoe Saldana"
    [3]=>
    string(10) "Karl Urban"
    [4]=>
    string(10) "Simon Pegg"
  }
  ["directors"]=>
  array(1) {
    [0]=>
    string(11) "J.J. Abrams"
  }
  ["writers"]=>
  array(4) {
    [0]=>
    string(12) "Roberto Orci"
    [1]=>
    string(13) "Alex Kurtzman"
    [2]=>
    string(14) "Damon Lindelof"
    [3]=>
    string(16) "Gene Roddenberry"
  }
  ["genres"]=>
  array(4) {
    [0]=>
    string(6) "Action"
    [1]=>
    string(9) "Adventure"
    [2]=>
    string(6) "Sci-Fi"
    [3]=>
    string(8) "Thriller"
  }
  ["movie_data"]=>
  array(12) {
    ["imdb_id"]=>
    string(9) "tt1408101"
    ["slug"]=>
    string(23) "star-trek-into-darkness"
    ["title"]=>
    string(23) "Star Trek Into Darkness"
    ["imdb_rating"]=>
    string(3) "8.2"
    ["release_date"]=>
    string(11) "6 June 2013"
    ["runtime"]=>
    string(4) "132m"
    ["mpaa_rating"]=>
    string(5) "PG-13"
    ["storyline"]=>
    string(554) "When the crew of the Enterprise is called back home, they find an unstoppable force of terror from within their own organization has detonated the fleet and everything it stands for, leaving our world in a state of crisis. With a personal score to settle, Captain Kirk leads a manhunt to a war-zone world to capture a one man weapon of mass destruction. As our heroes are propelled into an epic chess game of life and death, love will be challenged, friendships will be torn apart, and sacrifices must be made for the only family Kirk has left: his crew."
    ["plot"]=>
    string(202) "After the crew of the Enterprise find an unstoppable force of terror from within their own organization, Captain Kirk leads a manhunt to a war-zone world to capture a one man weapon of mass destruction."
    ["poster_large"]=>
    bool(false)
    ["poster"]=>
    string(97) "http://ia.media-imdb.com/images/M/MV5BMTk2NzczOTgxNF5BMl5BanBnXkFtZTcwODQ5ODczOQ@@._V1._SY500.jpg"
    ["trailer"]=>
    string(157) "http://www.youtube.com/v/QAEkuVgt6Aw&feature=youtube_gdata_player?color2=FBE9EC&hd=1&autoplay=1&showsearch=0&version=3&modestbranding=1&fs=1&iv_load_policy=3"
  }
}

我在一个普通数组中有一个名为“stars”的数组,希望该“stars”数组中的所有值都位于数据库的一个字段中。当然,我们称之为stars,以便于匹配和搜索

我已经看过codeigniters批处理插入函数,但它不希望我需要它

我希望至少有人能为我指明正确的方向,告诉我如何继续下去

先谢谢你


你应该先阅读


一个建议:为了满足您的需要,搜索MongoDB。

MySQL没有数组字段类型。使用MySQL,您需要以下样式的两个表:

films
id | FilmName
1    Star Trek

actors
id | FilmId | Name 
1    1        Chris Pine
2    1        Zachary Quinto
3    1        Zoe Saldana
您可以通过中间的链接表进一步了解这一点,这样,无论演员拍了多少部电影,每个演员都只有一行

在CI中,插入电影后,可以插入每个“演员”行。如果在表中使用类似InnoDB的东西,也可以通过事务()来实现


如果这是不可能的(为什么它不是?),你应该考虑一个基于NoSQL的数据库,比如MangGDB。我需要重新思考我的数据库将如何构建。我现在有一个foreach循环,它将电影中的所有演员压缩成一个字符串。但我认为你的想法可能是更好的解决办法我在数据库中插入数组没有问题,这很好,我只是在嵌套数组中遇到了一些问题。不过还是谢谢你。