$dbHost = '127.0.0.1';
$dbUser = 'root';
$dbPassword = '';
$opt = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
$pdo = new PDO ( "mysql:host=$dbHost; charset=utf8", $dbUser, $dbPassword );
$stmt = $pdo->prepare('CREATE DATABASE IF NOT EXISTS table_table' );
$result = $stmt->execute();
$pdo = new PDO ( "mysql:host=$dbHost; dbname=table_table; charset=utf8", $dbUser, $dbPassword );
$stmt = $pdo->prepare( "CREATE TABLE boxes ( box_id INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY, box_name VARCHAR(64) NOT NULL )");
$result = $stmt->execute();
$pdo = new PDO ( "mysql:host=$dbHost; dbname=table_table; charset=utf8", $dbUser, $dbPassword );
$stmt = $pdo->prepare( "CREATE TABLE fruits ( fruit_id INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY, fruit_name VARCHAR(64) NOT NULL )");
$result = $stmt->execute();
$pdo = new PDO ( "mysql:host=$dbHost; dbname=table_table; charset=utf8", $dbUser, $dbPassword );
$stmt = $pdo->prepare( "CREATE TABLE descriptions ( description_id INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY, description_value VARCHAR(64) NOT NULL )");
$result = $stmt->execute();
$pdo = new PDO ( "mysql:host=$dbHost; dbname=table_table; charset=utf8", $dbUser, $dbPassword );
$stmt = $pdo->prepare( "CREATE TABLE boxes_fruits_descriptions ( id INT(11) UNSIGNED AUTO_INCREMENT PRIMARY KEY, box_id INT(11) UNSIGNED, fruit_id INT(11) UNSIGNED, description_id INT(11) UNSIGNED )");
$result = $stmt->execute();
$pdo = new PDO ( "mysql:host=$dbHost; dbname=table_table; charset=utf8", $dbUser, $dbPassword );
$stmt = $pdo->prepare( "ALTER TABLE boxes_fruits_descriptions ADD FOREIGN KEY (`box_id`) REFERENCES `boxes`(`box_id`) ON DELETE RESTRICT ON UPDATE RESTRICT;");
$result = $stmt->execute();
$pdo = new PDO ( "mysql:host=$dbHost; dbname=table_table; charset=utf8", $dbUser, $dbPassword );
$stmt = $pdo->prepare( "ALTER TABLE boxes_fruits_descriptions ADD FOREIGN KEY (`fruit_id`) REFERENCES `fruits`(`fruit_id`) ON DELETE RESTRICT ON UPDATE RESTRICT;");
$result = $stmt->execute();
$pdo = new PDO ( "mysql:host=$dbHost; dbname=table_table; charset=utf8", $dbUser, $dbPassword );
$stmt = $pdo->prepare( "ALTER TABLE boxes_fruits_descriptions ADD FOREIGN KEY (`description_id`) REFERENCES `descriptions`(`description_id`) ON DELETE RESTRICT ON UPDATE RESTRICT;");
$result = $stmt->execute();