# TARQORA Black Galaxy Granite - MySQL & PHP Database Integration Guide This guide explains how to integrate your website and Admin Panel with a **PHP & MySQL** backend (on cPanel, phpMyAdmin, Apache/Nginx, Localhost XAMPP, or a Linux VPS). --- ## 📁 Included Backend Files 1. **`schema.sql`**: Production MySQL database dump creating all 6 tables (`tarqora_gallery`, `tarqora_countries`, `tarqora_slider`, `tarqora_seo`, `tarqora_leads`, `tarqora_settings`) with pre-seeded data for all slabs, export markets, and settings. 2. **`db_connect.php`**: Secure PDO MySQL database connection script with UTF-8 encoding. 3. **`api.php`**: Complete RESTful JSON API providing CRUD operations for Gallery, Countries, Slider, SEO, Leads, and full database sync. 4. **`test_connection.php`**: Diagnostic health check script to verify PHP extensions and MySQL credentials. --- ## 🚀 3-Step Setup Instructions ### Step 1: Import `schema.sql` into MySQL - **Using phpMyAdmin (cPanel or Localhost)**: 1. Open phpMyAdmin. 2. Create a new database named `tarqora_granite_db` (or any name you choose) with collation `utf8mb4_unicode_ci`. 3. Click the **Import** tab at the top. 4. Choose `schema.sql` from this folder and click **Import** (or **Go**). 5. All tables and default data will be created automatically. - **Using MySQL Command Line**: ```bash mysql -u root -p -e "CREATE DATABASE IF NOT EXISTS tarqora_granite_db CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci;" mysql -u root -p tarqora_granite_db < schema.sql ``` --- ### Step 2: Configure MySQL Credentials in `db_connect.php` Open `db_connect.php` and set your MySQL server credentials: ```php define('DB_HOST', '127.0.0.1'); // Usually 'localhost' or '127.0.0.1' define('DB_PORT', '3306'); // Default MySQL port define('DB_NAME', 'tarqora_granite_db'); // Your database name define('DB_USER', 'your_mysql_username'); // MySQL user define('DB_PASS', 'your_mysql_password'); // MySQL password ``` --- ### Step 3: Connect the Admin Panel to PHP API 1. Navigate to the Admin Panel: **Admin Dashboard → MySQL & PHP Database**. 2. Enter your PHP API Endpoint URL (e.g. `https://your-domain.com/backend/api.php` or `http://localhost/tarqora/backend/api.php`). 3. Click **"Test Connection"** to verify the link. 4. Click **"Sync All Current State to MySQL"** to push your gallery items, slider, and country specs straight into your MySQL database! --- ## 📡 API Endpoints Reference (`api.php`) | Method | Action | Description | |---|---|---| | `GET` | `?action=test` | Verifies MySQL connection and returns table row counts | | `GET` | `?action=get_all` | Returns complete database snapshot (Gallery, Slider, Countries, SEO, Leads, Settings) | | `POST` | `?action=save_gallery_item` | Creates or updates a gallery slab asset | | `POST` | `?action=delete_gallery_item` | Deletes a gallery slab asset by ID | | `POST` | `?action=save_country` | Updates target export country specs, ports, transit time, and currency | | `POST` | `?action=save_slider` | Updates homepage 5-stage slider items | | `POST` | `?action=save_seo` | Updates page SEO metadata | | `POST` | `?action=submit_lead` | Logs a new wholesale container RFQ inquiry | | `POST` | `?action=update_lead_status` | Updates lead status (New, Contacted, Quoted, Closed) and notes | | `POST` | `?action=sync_all` | Bulk syncs entire website state from Admin to MySQL | | `GET` | `?action=export_sql` | Generates and downloads a fresh `.sql` file |