I have an array in php:
Code: Select all
$arr = array(3, 'value 1', 'other value');
I want to store /insert the $arr array in the "data" column, then to can select and use it in php.
How can I do this, how can I store a php array in mysql?
Code: Select all
$arr = array(3, 'value 1', 'other value');
Code: Select all
$arr = array(3, 'value 1', 'other value');
$sql = "INSERT INTO table (name, data)
VALUES ('The Name', '". json_encode($arr) ."')";
// ...
Code: Select all
[3,"value 1","other value"]
Code: Select all
// Performs the Select ..
$arr = json_decode($row['data'], true); // add true to convert into array