I’m very new to MySQL, although I’ve used SQL databases in other contexts before. I have a test site set up which has an online cPanel with access to phpMyAdmin. I’m attempting to setup a MySQL database, and so far it’s working fine (I can connect to the Database and the table).
The only problem I’m having is with inserting data. I’d like to insert an entire array (specifically, the array will be a double[]) into one column. After looking at the column types available in phpMyAdmin, it doesn’t seem to support inserting arrays other than Binary arrays.
I’ve found many solutions for inserting arrays programatically including this thread, but for this site we will be inserting data via the online cPanel. Is there a way to do that?
If you want access to that data, and want to be able to use the power of SQL to search in your double[], you should do it this way:
First, you should spend some time researching relational databases. They allow you to create linked data.
An important part of every relational database is using good keys. A key is a unique identifier for a row that allows you to access the data on that row in an efficient manner.
Another important part of relational databases are indexes. Indexes are not required to be unique. But are useful if you are trying to search on them (SQL has made an “index” of the table based on a column or group of columns)
If you wanted to create a table that would have a double[] array, you might instead create a 2nd table that relates to the first table by the first tables primary key.
To get the information back out that you want, you can select using a
JOINstatement. If you wanted to get all the information where the base_id was 3, you would write it like so:The advanced form of writing this with aliasing
If you don’t want to have access to the data, but are just recalling it, you should do it this way: (Although this is debatable, I still recommend the above way, if you are willing to learn more sql)
I assume you will be using PHP, we will be serializing the data (see: http://php.net/manual/en/function.serialize.php)
Note we will don’t have the darray table, but instead add a
to the base table.
Inserting with PHP serialized data
Getting the serialized data