A minimal portal to display library resources (title, publisher, subject, year, link), with CSV import and CSV export.
- Display table with columns: Title, Publisher, Subject, Year, Link
- Optional search (Title/Publisher/Subject)
- Upload a CSV to import (headers required:
title,publisher,subject,year,link
) - Export all records as CSV
- Uses PDO with prepared statements
-
Create a MySQL database (e.g.,
resource_portal
) and user.CREATE DATABASE resource_portal CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; CREATE USER 'portal_user'@'%' IDENTIFIED BY 'addyourpasswordhere'; GRANT ALL PRIVILEGES ON resource_portal.* TO 'portal_user'@'%'; FLUSH PRIVILEGES;
-
Import the schema:
mysql -u portal_user -p resource_portal < resource_portal.sql
-
Update
config.php
with your DB credentials. -
Copy all files to your PHP server (Apache/Nginx with PHP 8+). Make sure
uploads/
is writable:mkdir -p uploads chmod 775 uploads
-
Open
index.php
in your browser.
- Header row is required and must exactly be:
title,publisher,subject,year,link
- Example:
title,publisher,subject,year,link Data Science 101,O'Reilly,Data,2021,https://example.com/ds101 Library Automation Basics,Springer,Library Science,2019,https://example.com/lab
config.php
– database credentialsdb.php
– PDO connection helperschema.sql
– table DDLindex.php
– list view + search + upload form + export linkimport.php
– CSV processing + importexport.php
– CSV export of all rowssample.csv
– example CSV
- Edit/Delete: On
index.php
, each row has Edit and Delete (admin login required).edit.php
updates fields.delete.php
removes a record.
- Auto-Remove Duplicates:
- Table now has a deterministic
checksum
(MD5 over normalized fields) with a UNIQUE index. - Imports use
INSERT IGNORE
, so rows that would duplicate an existing record are skipped automatically. - To clean up historical duplicates once, run:
php dedupe.php
- Table now has a deterministic
If you have an existing resources
table, run these:
ALTER TABLE resources
ADD COLUMN checksum CHAR(32) GENERATED ALWAYS AS (
MD5(CONCAT_WS('|',
LOWER(TRIM(title)),
LOWER(TRIM(COALESCE(publisher,''))),
LOWER(TRIM(COALESCE(subject,''))),
LPAD(COALESCE(CAST(year AS CHAR),''),4,'0'),
LOWER(TRIM(COALESCE(link,'')))
))
) STORED,
ADD UNIQUE KEY uq_resources_checksum (checksum);
Then (optionally) remove old duplicates:
php dedupe.php