How to add a column of type array using phpMyAdmin or sql
P粉012875927
P粉012875927 2024-03-27 00:18:52
0
1
434

How to use phpMyAdmin to add a column of type array Know Change the table name and add column listid integer array; Change table name and add column listid integer []; Not working

P粉012875927
P粉012875927

reply all(1)
P粉764003519

As mentioned in the comments, arrays are not types. You can choose to use a separate table to hold the elements in the array and have them have a foreign key that references the original table, or parse the array into a string each time and store it as text, depending on your needs.

CREATE TABLE orders (
  id INT NOT NULL PRIMARY KEY,
  description TEXT,
  reference TEXT
  -- This is where you'd want to add your list of order lines
);

-- Instead, we'll create an orderline table referring back to the orders
CREATE TABLE orderlines (
  id INT NOT NULL PRIMARY KEY,
  description TEXT,
  order_id INT REFERENCES orders(id)
);

Now you can put the array values ​​(I'm assuming for now the order lines) into their own separate table. To query them you can do this

SELECT * FROM orders
LEFT JOIN orderlines ON orderlines.order_id = orders.id;

You can use subqueries to be smart enough to return an array, especially in your application.

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!