// if could not connect to database if (!($connection = @mysql_connect($MySQL_host, $MySQL_username, $MySQL_password))) { // stop execution and display error message die('Error connecting to the database!<br>Make sure you have specified correct values for host, username and password.'); } // if database could not be selected if (!@mysql_select_db($MySQL_database, $connection)) { // stop execution and display error message die('Error selecting database!<br>Make sure you have specified an existing and accessible database.'); } // first, clear everything in the database mysql_query('TRUNCATE TABLE mptt'); // include the Zebra_Mptt class require '../Zebra_Mptt.php'; // instantiate the Zebra_Mptt object $mptt = new Zebra_Mptt(); // populate the table // add 'Food' as a topmost node $food = $mptt->add(0, 'Food'); // 'Fruit' and 'Meat' are direct descendants of 'Food' $fruit = $mptt->add($food, 'Fruit'); $meat = $mptt->add($food, 'Meat'); // 'Red' and 'Yellow' are direct descendants of 'Fruit' $red = $mptt->add($fruit, 'Red'); $yellow = $mptt->add($fruit, 'Yellow'); // add a fruit of each color $mptt->add($red, 'Cherry'); $mptt->add($yellow, 'Banana'); // add two kinds of meat $mptt->add($meat, 'Beef'); $mptt->add($meat, 'Pork');
<?php // database connection details $mysql_host = ''; $mysql_username = ''; $mysql_password = ''; $mysql_database = ''; // if could not connect to database $connection = @mysqli_connect($mysql_host, $mysql_username, $mysql_password) or die('Error connecting to the database!<br>Make sure you have specified correct values for host, username and password.'); // if database could not be selected @mysqli_select_db($connection, $mysql_database) or die('Error selecting database!<br>Make sure you have specified an existing and accessible database.'); // first, clear everything in the database mysqli_query($connection, 'TRUNCATE TABLE mptt'); // include the Zebra_Mptt class require '../Zebra_Mptt.php'; // instantiate the Zebra_Mptt object $mptt = new Zebra_Mptt($connection); // populate the table // add 'Food' as a topmost node $food = $mptt->add(0, 'Food'); // 'Fruit' and 'Meat' are direct descendants of 'Food' $fruit = $mptt->add($food, 'Fruit'); $meat = $mptt->add($food, 'Meat'); // 'Red' and 'Yellow' are direct descendants of 'Fruit' $red = $mptt->add($fruit, 'Red'); $yellow = $mptt->add($fruit, 'Yellow'); // add a fruit of each color $cherry = $mptt->add($red, 'Cherry'); $banana = $mptt->add($yellow, 'Banana'); // add a color, but in the wrong position $orange = $mptt->add($banana, 'Orange'); // now move it to fruits, after the "red" node