Crew-Portal Posted November 12, 2007 Share Posted November 12, 2007 Is there any simple way to take a array and punch in into a mysql query or am I going to have to insert each array by itself? Link to comment https://forums.phpfreaks.com/topic/77003-array-to-mysql/ Share on other sites More sharing options...
revraz Posted November 12, 2007 Share Posted November 12, 2007 Give us an example of what you are trying to do. You can do pretty much anything with an Array and MySQL Link to comment https://forums.phpfreaks.com/topic/77003-array-to-mysql/#findComment-389910 Share on other sites More sharing options...
rajivgonsalves Posted November 12, 2007 Share Posted November 12, 2007 if your array keys are same as your mysql field names it would be easy eg. or you have the same length of array elements as your mysql table consider the following code $arrData = array("username"=>"rajivgonsalves", "password"=>"somepassword", "location"=>"India"); $sqlQuery = "insert into $tablename (".implode(",",array_keys($arrData))." VALUES ('".implode("','",array_values($arrData))."'"; echo $sqlQuery; $sqlQuery = "insert into $tablename VALUES ('".implode("','",array_values($arrData))."'"; echo $sqlQuery; Link to comment https://forums.phpfreaks.com/topic/77003-array-to-mysql/#findComment-389912 Share on other sites More sharing options...
Pavel11 Posted November 12, 2007 Share Posted November 12, 2007 If you want save a array in database you may serialise (http://www.php.net/manual/ru/function.serialize.php) it and save as string. For restore a array you must unserialise it. But if you use this way you can't operate with certain elements of array in database(select, update, etc.) Link to comment https://forums.phpfreaks.com/topic/77003-array-to-mysql/#findComment-389961 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.