Jump to content

array to mysql?


Crew-Portal

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.