PHP code example of dfba / schema

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

    

dfba / schema example snippets


Dfba\Schema\Laravel\SchemaServiceProvider::class,


namespace App\Http\Controllers;

use Illuminate\Routing\Controller as BaseController;

use Dfba\Schema\Schema; // Very crucial line

class ExampleController extends BaseController {
    
	public function test(Schema $schema) {
		// --------------^ HERE


		// Some demo code:
		echo "<b>". $schema->getName() ."</b><br>";

		foreach ($schema->getTables() as $table) {
			echo "__ <b>". $table->getName() ."</b><br>";

			foreach ($table->getColumns() as $column) {
				echo "__ __ <b>". 
					$column->getName() ."</b><br>";

				echo "__ __ __ <i>dataType:</i> ".
					$column->getDataType() ."<br>";
				echo "__ __ __ <i>unsigned:</i> ".
					$column->getUnsigned() ."<br>";
				echo "__ __ __ <i>zerofill:</i> ".
					$column->getZerofill() ."<br>";
				echo "__ __ __ <i>nullable:</i> ".
					$column->getNullable() ."<br>";
				echo "__ __ __ <i>defaultValue:</i> ".
					$column->getDefaultValue() ."<br>";
				echo "__ __ __ <i>options:</i> ".
					implode(', ', $column->getOptions() ?: []) ."<br>";
				echo "__ __ __ <i>autoIncrement:</i> ".
					$column->getAutoIncrement() ."<br>";
				echo "__ __ __ <i>maximumLength:</i> ".
					$column->getMaximumLength() ."<br>";
				echo "__ __ __ <i>minimumValue:</i> ".
					$column->getMinimumValue() ."<br>";
				echo "__ __ __ <i>maximumValue:</i> ".
					$column->getMaximumValue() ."<br>";
				echo "__ __ __ <i>precision:</i> ".
					$column->getPrecision() ."<br>";
				echo "__ __ __ <i>scale:</i> ".
					$column->getScale() ."<br>";
				echo "__ __ __ <i>characterSet:</i> ".
					$column->getCharacterSet() ."<br>";
				echo "__ __ __ <i>collation:</i> ".
					$column->getCollation() ."<br>";
				echo "__ __ __ <i>comment:</i> ".
					$column->getComment() ."<br>";
			}
		}

	}
}


namespace App\Http\Controllers;

use Illuminate\Routing\Controller as BaseController;

use Dfba\Schema\Manager; // Very crucial line

class ExampleController extends BaseController {

	public function test(Manager $manager) {
		
		$anyRandomPdo = \DB::connection()->getReadPdo();
		$someSchemaName = 'example';

		$schema = $manager->getSchema($anyRandomPdo, $someSchemaName);

		var_dump($schema);
		
	}
}

$schemaManager = new Dfba\Schema\Manager();
$anyRandomPdo = new PDO("mysql:host=localhost;dbname=example", "username", "password");
$someSchemaName = 'example';

$schema = $schemaManager->getSchema($anyRandomPdo, $someSchemaName);

var_dump($schema);