Database Setup (Optional)
Trongate gives you complete flexibility – you can build powerful web applications with or without a database. If your project requires storing or retrieving data, you can connect Trongate to a MySQL or MariaDB database. If you do not need a database, you can safely skip this step.
Step 1: Create a Database (Optional)
If your application will use a database, the first step is to create one. This can be done via your hosting control panel (such as cPanel or Plesk), phpMyAdmin, or directly from the MySQL/MariaDB command line. For example, in phpMyAdmin:
- Open phpMyAdmin from your hosting control panel.
- Click on the Databases tab.
- Enter a name for your new database (for example,
trongate_app). - Click Create.
Make a note of your database name, username, and password if you create one.
Step 2: Locate the Database Configuration File
Database connection settings are stored inside
config/database.php. Open this file in your editor and you
will see sample settings like the following:
<?php
// Database settings
define('HOST', '127.0.0.1');
define('PORT', '3306');
define('USER', 'root');
define('PASSWORD', '');
define('DATABASE', '');
Step 3: Update the Settings
If you created a database, replace the sample values with your actual connection details:
- HOST – usually
127.0.0.1orlocalhost. Some hosts may provide a different server name. - PORT – usually
3306unless your host specifies otherwise. - USER – your database username.
- PASSWORD – your database password.
- DATABASE – the name of your database.
Step 4: Save and Continue
After saving your changes, Trongate will attempt to connect to the database whenever it is needed. If you do not intend to use a database, simply leave the default values in place – Trongate will continue to run without issue.
Step 5: Setting Up Starter Tables
To get the most out of Trongate, it is advisable to create a few starter database tables. These tables provide essential functionality for things like user management, tokens, and administrator access.
Below you’ll find a set of SQL statements that will create the recommended starter tables. Simply copy the SQL code into your database management tool (such as phpMyAdmin, Adminer, or the MySQL command line) and execute it.
CREATE TABLE `trongate_administrators` (
`id` int(11) NOT NULL,
`username` varchar(65) DEFAULT NULL,
`password` varchar(60) DEFAULT NULL,
`trongate_user_id` int(11) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
INSERT INTO `trongate_administrators` (`id`, `username`, `password`, `trongate_user_id`) VALUES
(1, 'admin', '$2y$11$SoHZDvbfLSRHAi3WiKIBiu.tAoi/GCBBO4HRxVX1I3qQkq3wCWfXi', 1);
CREATE TABLE `trongate_comments` (
`id` int(11) NOT NULL,
`comment` text DEFAULT NULL,
`date_created` int(11) DEFAULT 0,
`user_id` int(11) DEFAULT NULL,
`target_table` varchar(125) DEFAULT NULL,
`update_id` int(11) DEFAULT NULL,
`code` varchar(6) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
CREATE TABLE `trongate_tokens` (
`id` int(11) NOT NULL,
`token` varchar(125) DEFAULT NULL,
`user_id` int(11) DEFAULT 0,
`expiry_date` int(11) DEFAULT NULL,
`code` varchar(3) DEFAULT '0'
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
CREATE TABLE `trongate_users` (
`id` int(11) NOT NULL,
`code` varchar(32) DEFAULT NULL,
`user_level_id` int(11) DEFAULT 0
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
INSERT INTO `trongate_users` (`id`, `code`, `user_level_id`) VALUES
(1, 'rSGf3dn6UeDZzJ9spCWCrTmxzp6zc5w6', 1);
CREATE TABLE `trongate_user_levels` (
`id` int(11) NOT NULL,
`level_title` varchar(125) DEFAULT ''
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
INSERT INTO `trongate_user_levels` (`id`, `level_title`) VALUES
(1, 'admin');
ALTER TABLE `trongate_administrators`
ADD PRIMARY KEY (`id`);
ALTER TABLE `trongate_comments`
ADD PRIMARY KEY (`id`);
ALTER TABLE `trongate_tokens`
ADD PRIMARY KEY (`id`);
ALTER TABLE `trongate_users`
ADD PRIMARY KEY (`id`);
ALTER TABLE `trongate_user_levels`
ADD PRIMARY KEY (`id`);
ALTER TABLE `trongate_administrators`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;
ALTER TABLE `trongate_comments`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
ALTER TABLE `trongate_tokens`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT;
ALTER TABLE `trongate_users`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;
ALTER TABLE `trongate_user_levels`
MODIFY `id` int(11) NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=2;
Once executed, your database will contain the essential tables needed for user authentication, access levels, administrator accounts, tokens, and comments. These starter tables can be customised later to suit your project’s requirements.
Troubleshooting & Getting Help
- Check your database name, username, and password for typos.
- Confirm your database user has permission to access the database.
- If you are using shared hosting, the database host may not be
localhost– check your host’s documentation. - If you do not plan to use a database, you can safely ignore connection errors.
If you encounter issues or want to learn more about working with databases in Trongate, help is always available: