PHP Classes

File: example/example.php

Recommend this page to a friend!
  Classes of Rafael Lúcio   SQLTools   example/example.php   Download  
File: example/example.php
Role: Example script
Content type: text/plain
Description: Example script
Class: SQLTools
Create and alter databases, tables and indexes
Author: By
Last change: Update of example/example.php
Date: 11 months ago
Size: 916 bytes
 

Contents

Class file image Download
<?php

require_once __DIR__ . '/../vendor/autoload.php';

use
SQLTools\Command\CreateDataBase;
use
SQLTools\Command\CreateTable;
use
SQLTools\Entity\Field;
use
SQLTools\SQLConfig;
use
SQLTools\SQLTools;

$dbName = "sql_tools_example";

$config = new SQLConfig("localhost", "root");

SQLTools::configure($config);

SQLTools::execute(new CreateDataBase($dbName));

$config->setDb($dbName);


$idField = new Field("id", "INT", null, false, null, true, false, 'AUTO_INCREMENT');

$nameField = new Field("name", "VARCHAR", 100, false);

$descriptionField = new Field("description", "TEXT");

$dateField = new Field("date", "DATE");

$command = new CreateTable("event", array($idField, $nameField, $descriptionField, $dateField));

$errorInfo = SQLTools::execute($command)->errorInfo();

if (!empty(
$errorInfo) && $errorInfo[0] != '00000')
{
   
print_r($errorInfo);
}

else
{
    echo
"Everything is gonna be alright";
}