#1 2025-04-21 22:07:15

Dave_G
Member
2019-03-24
17

How to export a list of albums from the database?

Hello,

I'm running Piwigo 15.3.0 on a self-hosted server, with MariaDB 11.3.2 as the database engine. My site has a few hundred albums, and I would like to extract a list of the album names from the database. I'm fairly fluent in SQL and working with MariaDB, but so far I haven't been able to find a table that contains the album names. Would someone be able to point me in the right direction?

I did try

Code:

SELECT * FROM items WHERE type='album';

which provided me with a list of albums, but it was incomplete, only showing albums that were years old, and nothing newer.

I also found the Export Data plugin, which did export a list of album names, but the list was also incomplete, missing the more recent albums.

Thanks!

Last edited by Dave_G (2025-04-21 22:26:06)

Offline

 

#2 2025-04-21 23:56:23

windracer
Member
St. Pete, FL
2014-12-28
582

Re: How to export a list of albums from the database?

I don't have an items table, I wonder if that's left over from an older version?

I think the categories table is what you're looking for.

Offline

 

#3 2025-05-01 16:10:04

alidemir
Member
istanbul
2025-05-01
10

Re: How to export a list of albums from the database?

To export a complete list of album names from your Piwigo database, the issue is that the albums themselves are stored in several related tables, and not all albums are listed in the items table directly. Here's how you can query the correct tables to get a comprehensive list of albums:

1. Key Tables Involved:
piwigo_albums (or whatever your album table is named based on your Piwigo installation).

piwigo_categories (this table stores album-related data, including album names).

piwigo_items (this is where the individual images or items are listed).

The items table contains entries for both images and albums, but you need to use the correct joins to pull album names across all relevant records.

2. SQL Query to Export All Albums:
The albums themselves are stored as categories in Piwigo, and you will most likely want to query the categories table to fetch album names. Below is a general query that should pull the full list of album names:

sql
Kopyala
Düzenle
SELECT c.name AS album_name, c.id_category AS album_id
FROM piwigo_categories AS c
WHERE c.id_category IN (
    SELECT DISTINCT category_id FROM piwigo_category_element
)
ORDER BY c.name;
Explanation of the query:
piwigo_categories table contains all the album names (name) and their IDs (id_category).

piwigo_category_element is a relationship table that links categories (albums) to items (images). The subquery ensures that you only get categories that are actively linked to images.

The DISTINCT category_id ensures you don't get duplicate album names.

3. Alternative Query (If categories Table Is Named Differently):
If your table names are slightly different (due to customizations or different versions), this query should still guide you, but the piwigo_categories and piwigo_category_element table names may vary. Here's another variation:

sql
Kopyala
Düzenle
SELECT cat.name AS album_name
FROM piwigo_category AS cat
JOIN piwigo_category_element AS cat_elem
ON cat.id_category = cat_elem.category_id
ORDER BY cat.name;
4. Exporting the List:
Once you run the query, you can export the results to a CSV or any other format via your database management tool (phpMyAdmin, Adminer, or command-line tools).

5. Possible Issue with the items Table:
You mentioned that querying the items table for albums gave incomplete results. This can happen if:

Not all albums are assigned correctly in the items table.

Some albums may not have items associated with them yet (though the category_element table should handle this).

Make sure your query to piwigo_category_element is retrieving the right data, as it will give you a more complete view.

6. Check for Missing Albums:
If albums are missing, you might want to check if they have associated images or if they are truly empty. You can run a query like this to find albums with no items:

sql
Kopyala
Düzenle
SELECT c.name AS album_name
FROM piwigo_categories AS c
LEFT JOIN piwigo_category_element AS ce ON c.id_category = ce.category_id
WHERE ce.element_id IS NULL
ORDER BY c.name;
This query finds albums that do not have any items linked to them.

Offline

 

#4 2025-05-02 23:37:11

Dave_G
Member
2019-03-24
17

Re: How to export a list of albums from the database?

Wow, thanks for that really thorough reply! However, my piwigo database doesn't contain piwigo_albums or piwigo_items tables. It does contain the piwigo_categories table, but that does not have a field called piwigo_category_element:

Code:

> SHOW COLUMNS FROM piwigo_categories;
+---------------------------+--------------------------+------+-----+---------------------+-------------------------------+
| Field                     | Type                     | Null | Key | Default             | Extra                         |
+---------------------------+--------------------------+------+-----+---------------------+-------------------------------+
| id                        | smallint(5) unsigned     | NO   | PRI | NULL                | auto_increment                |
| name                      | varchar(255)             | NO   |     |                     |                               |
| id_uppercat               | smallint(5) unsigned     | YES  | MUL | NULL                |                               |
| comment                   | text                     | YES  |     | NULL                |                               |
| dir                       | varchar(255)             | YES  |     | NULL                |                               |
| rank                      | smallint(5) unsigned     | YES  |     | NULL                |                               |
| status                    | enum('public','private') | NO   |     | public              |                               |
| site_id                   | tinyint(4) unsigned      | YES  |     | NULL                |                               |
| visible                   | enum('true','false')     | NO   |     | true                |                               |
| representative_picture_id | mediumint(8) unsigned    | YES  |     | NULL                |                               |
| uppercats                 | varchar(255)             | NO   |     |                     |                               |
| commentable               | enum('true','false')     | NO   |     | true                |                               |
| global_rank               | varchar(255)             | YES  |     | NULL                |                               |
| image_order               | varchar(128)             | YES  |     | NULL                |                               |
| permalink                 | varchar(64)              | YES  | UNI | NULL                |                               |
| lastmodified              | timestamp                | NO   | MUL | current_timestamp() | on update current_timestamp() |
| community_user            | mediumint(8) unsigned    | YES  |     | NULL                |                               |
| menurandomphoto_active    | enum('true','false')     | YES  |     | false               |                               |
| downloadable              | enum('true','false')     | YES  |     | true                |                               |
| paypal_active             | enum('true','false')     | YES  |     | false               |                               |
+---------------------------+--------------------------+------+-----+---------------------+-------------------------------+
20 rows in set (0.001 sec)

I'm running Piwigo 15.3.0 and MariaDB 11.3.2.

But at any rate, I was able to extract the list of my albums with the Export Data plugin.

Offline

 

#5 2025-05-03 21:19:50

AthLux
Member
2017-03-04
22

Re: How to export a list of albums from the database?

In my piwigo database the images are in the table "piwigo_images".
I also have no table "piwigo_albums" but alidemir also don't use this table in his queries.

Offline

 

Board footer

Powered by FluxBB

github twitter newsletter Donate Piwigo.org © 2002-2025 · Contact