PHP code example of farisc0de / phpmigration

1. Go to this page and download the library: Download farisc0de/phpmigration library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

farisc0de / phpmigration example snippets




use Farisc0de\PhpMigration\Database;
use Farisc0de\PhpMigration\Options\Options;
use Farisc0de\PhpMigration\Options\Types;
use Farisc0de\PhpMigration\Utils;
use Farisc0de\PhpMigration\Migration;

$obj = new Migration(new Database($config), new Utils());

if ($_SERVER['REQUEST_METHOD'] == 'POST') {

    // Create a new table
    $obj->createTable(
        "users",
        [
            ["id", Types::Integer(), Options::AutoIncrement(), Options::NotNull()],
            ["username", Types::String(255), Options::NotNull()],
            ["password", Types::String(255), Options::NotNull()],
            ["email", Types::String(255), Options::NotNull()],
            ["created_at", Types::TimeStamp(), Options::CurrentTimeStamp()],
            ["updated_at", Types::TimeStamp(), Options::CurrentTimeStamp()]
        ]
    );

    // Create Primary Key
    $obj->setPrimary("users", "id");

    // Add a new record
    $obj->insertValue(
        "users",
        [
            "username" => "admin",
            "password" => password_hash("admin", PASSWORD_DEFAULT),
            "email" => "[email protected]",
        ]
    );

    $msg = "Database installed successfully!";