luke101 Posted August 25, 2007 Share Posted August 25, 2007 Is it possible to insert php array directly in a mysql database? If so, how would I do this and do you think you could give an example? Link to comment https://forums.phpfreaks.com/topic/66654-insert-php-array-in-database/ Share on other sites More sharing options...
Barand Posted August 25, 2007 Share Posted August 25, 2007 Not directly, you have to convert to a string of delimited elements <?php $data = array (1,2,3,4,5); $items = join ('|', $data); // --> "1|2|3|4|5" ?> Now you can write $items to the table. BUT whenever you have the need to this, 9 times out of 10 you should be normalizing the data and writing each value to its own row in a separate table. Link to comment https://forums.phpfreaks.com/topic/66654-insert-php-array-in-database/#findComment-333950 Share on other sites More sharing options...
dbo Posted August 25, 2007 Share Posted August 25, 2007 How about serialize and unserialize? Link to comment https://forums.phpfreaks.com/topic/66654-insert-php-array-in-database/#findComment-333966 Share on other sites More sharing options...
Barand Posted August 25, 2007 Share Posted August 25, 2007 Overkill IMO, unless it's a multidimensional array. Link to comment https://forums.phpfreaks.com/topic/66654-insert-php-array-in-database/#findComment-333968 Share on other sites More sharing options...
dbo Posted August 25, 2007 Share Posted August 25, 2007 Nods, fair enough Link to comment https://forums.phpfreaks.com/topic/66654-insert-php-array-in-database/#findComment-333979 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.