PHP code example of codewdev / tablegenerator

1. Go to this page and download the library: Download codewdev/tablegenerator 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/ */

    

codewdev / tablegenerator example snippets


define("TABLE_GEN_CONF", [
    "driver" => "mysql",
    "host" => "localhost",
    "port" => "3306",
    "dbname" => "nome_db",
    "username" => "root",
    "passwd" => "",
    "options" => [
        PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8",
        PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
        PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_OBJ,
        PDO::ATTR_CASE => PDO::CASE_NATURAL
    ]
]);



use CodeWdev\TableGenerator\TableGenerator;

"users", [
    "first_name" => "VARCHAR(10) NOT NULL",
    "last_name" => "VARCHAR(255) NOT NULL",
    "email" => "VARCHAR(255) UNIQUE NOT NULL",
    "password" => "VARCHAR(255) NOT NULL DEFAULT 0"
]);


//command to create the table
$user_data->create();


//adding columns to the table
$user_data->addColumn([
    "document" => "VARCHAR(10)",
    "company" => "VARCHAR(50) NOT NULL"
]);


//
//deleting a column
$user_data->dropColumn("company");


//deleting a table
$user_data->drop();