Replies: 1 comment
-
Try this. Using MySQL with PHPDesktop InstallerTo bundle MySQL with your PHPDesktop application and create a standalone installer, follow these steps: Method 1: Bundling MySQL Server with Your App1. Prepare MySQL Files
2. Configure MySQL for Portable UseCreate a [mysqld]
port=3307
datadir=./data
basedir=. 3. Add Startup ScriptsCreate a PHP script to manage MySQL (e.g., <?php
function start_mysql() {
$mysql_path = __DIR__.'/mysql/bin/mysqld.exe';
$command = '"'.$mysql_path.'" --defaults-file="'.__DIR__.'/mysql/my.ini" --standalone';
pclose(popen('start /B '. $command, 'r'));
}
function stop_mysql() {
exec(__DIR__.'/mysql/bin/mysqladmin.exe -u root shutdown');
}
?> 4. Modify Your Main ApplicationIn your main PHP file (e.g., <?php
require_once 'start_mysql.php';
start_mysql();
// Database connection
$db = new mysqli('localhost:3307', 'root', '', 'your_db');
// Register shutdown function
register_shutdown_function('stop_mysql');
?> Method 2: Using PHPDesktop Installer with MySQL1. Create Installation ScriptAdd this to your installer script (NSIS/InnoSetup):
2. Add MySQL InitializationInclude this in your installer:
3. Create Database SetupAdd a PHP script that runs on first launch: <?php
if (!file_exists('db_initialized.flag')) {
$connection = new mysqli('localhost:3307', 'root', '');
$connection->query("CREATE DATABASE IF NOT EXISTS myapp_db");
file_put_contents('db_initialized.flag', '1');
}
?> Method 3: Using Embedded MySQL Alternative (MariaDB)For a lighter solution, consider using MariaDB embedded:
Important Considerations
Sample Complete Package Structure
|
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
-
am currently runing xampp server locally on my pc and have mysql database connected to my application i wanted to convert my applicaton into a desktop installer. now my problem is that how do i use my database in my xampp server in the phpdesktop. any help
Beta Was this translation helpful? Give feedback.
All reactions