PHP Web Application create Installer scripts

Today, We want to share with you PHP Web Application create Installer scripts.In this post we will show you , hear for php project install script we will give you demo and example for implement.In this post, we will learn about How To Create User-Friendly PHP Script Installation with an example.

PHP Web Application create Installer scripts

There are the Following The simple About PHP Web Application create Installer scripts Full Information With Example and source code.

As I will cover this Post with live Working example to develop PHP Installer: Create PHP application install scripts, so the some major files and Directory structures for this example is following below.

Connecting to MySQL with PHP

database-app
->data(folder)
-->init.sql
->public
-->css
--->style.css
->templates
-->footer.php
-->header.php
->common.php
->config.php
->intall.php

database-app/data/init.sql

CREATE DATABASE memberlist;

use memberlist;

CREATE TABLE members (
	id INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY, 
	memberfname VARCHAR(30) NOT NULL,
	memberlname VARCHAR(30) NOT NULL,
	membermail VARCHAR(50) NOT NULL,
	memberage INT(3),
	membercity VARCHAR(50),
	date TIMESTAMP
);

database-app/config.php

<?php
$host       = "localhost";
$databaseuname   = "root";
$password   = "";
$dbname     = "memberlist";
$dsn        = "mysql:host=$host;dbname=$dbname";
$config_op    = array(
                PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION
              );

database-app/intall.php

<?php
require "config.php";

try {
    $connection = new PDO("mysql:host=$host", $databaseuname, $password, $config_op);
    $sql = file_get_contents("data/init.sql");
    $connection->exec($sql);
    
    echo "Database and table members created successfully.";
} catch(PDOException $error) {
    echo $sql . "<br>" . $error->getMessage();
}

database-app/common.php

<?php
function escape($html) {
    return htmlspecialchars($html, ENT_QUOTES | ENT_SUBSTITUTE, "UTF-8");
}

database-app/public/index.php

<?php include "templates/header.php"; ?>

<ul>
	<li><a href="create.php"><strong>Create</strong></a> - add a member</li>
	<li><a href="read.php"><strong>Read</strong></a> - find a member</li>
</ul>

<?php include "templates/footer.php"; ?>

database-app/public/create.php

<?php
if (isset($_POST['submit'])) {
    require "../config.php";
    require "../common.php";

    try  {
        $connection = new PDO($dsn, $databaseuname, $password, $config_op);
        
        $new_member = array(
            "memberfname" => $_POST['memberfname'],
            "memberlname" => $_POST['memberlname'],
            "membermail"  => $_POST['membermail'],
            "memberage"   => $_POST['memberage'],
            "membercity"  => $_POST['membercity']
        );

        $sql = sprintf(
                "INSERT INTO %s (%s) values (%s)",
                "members",
                implode(", ", array_keys($new_member)),
                ":" . implode(", :", array_keys($new_member))
        );
        
        $mystmt = $connection->prepare($sql);
        $mystmt->execute($new_member);
    } catch(PDOException $error) {
        echo $sql . "<br>" . $error->getMessage();
    }
}
?>

<?php require "templates/header.php"; ?>

<?php if (isset($_POST['submit']) && $mystmt) { ?>
    <blockquote><?php echo $_POST['memberfname']; ?> successfully added.</blockquote>
<?php } ?>

<h2>Add a Member</h2>

<form method="post">
    <label for="memberfname">Member Name</label>
    <input type="text" name="memberfname" id="memberfname">
    <label for="memberlname">Member Sir Name</label>
    <input type="text" name="memberlname" id="memberlname">
    <label for="membermail">Email of Member</label>
    <input type="text" name="membermail" id="membermail">
    <label for="memberage">Member Age</label>
    <input type="text" name="memberage" id="memberage">
    <label for="membercity">City</label>
    <input type="text" name="membercity" id="membercity">
    <input type="submit" name="submit" value="Submit">
</form>

<a href="index.php">Back to home</a>

<?php require "templates/footer.php"; ?>

database-app/public/templates/footer.php

<p>PHP Installer Create PHP application install scripts</p>
</body>

</html>

database-app/public/templates/header.php

<!doctype html>
<html lang="en">

<head>
	<meta charset="utf-8">
	<meta http-equiv="x-ua-compatible" content="ie=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">

	<title>Learn how to create an Installer of your PHP Project</title>

	<link rel="stylesheet" href="css/style.css">
</head>

<body>
	<h1>PHP Web Application Installer scripts</h1>

database-app/public/css/style.css

label {
	display: block;
	margin: 10px 0;
}

table {
	border-collapse: collapse;
	border-spacing: 0;
}

td,
th {
	padding: 15px;
	border-bottom: 1px solid #3d3d3d;
}

Angular 6 CRUD Operations Application Tutorials

Read :

Read Also:  Laravel 6 Join multiple tables Eloquent Examples

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about PHP Web Application create Installer scripts.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.