Source for file TeraWurflMySQLNestedSet.php
Documentation is available at TeraWurflMySQLNestedSet.php
* Tera_WURFL - PHP MySQL driven WURFL
* Tera-WURFL was written by Steve Kamerman, and is based on the
* Java WURFL Evolution package by Luca Passani and WURFL PHP Tools by Andrea Trassati.
* This version uses a MySQL database to store the entire WURFL file, multiple patch
* files, and a persistent caching mechanism to provide extreme performance increases.
* @package TeraWurflDatabase
* @author Steve Kamerman <stevekamerman AT gmail.com>
* @version Stable 2.1.3 $Date: 2010/09/18 15:43:21
* @license http://www.mozilla.org/MPL/ MPL Vesion 1.1
* Takes an existing table with data in ancestor..descendent hierarchial format
* and ALTERs the table by adding a right and left (`rt` and `lt`) columns. These
* columns contain the nested set relationships between the nodes. This makes certain
* lookups (like fallback trees) extremely simple and very fast.
* This class is used by Tera-WURFL's MySQL5 Nested Set Database Connector
* @package TeraWurflDatabase
* How deeply the recursion can go into the tree
public function __construct(MySQLi &$dbcon,$source_table,$index_table,$column_node_id,$column_parent_id,$column_left= 'lt',$column_right= 'rt'){
$query = sprintf("SELECT parent.%s FROM %s AS node, %s AS parent
WHERE node.%s BETWEEN parent.%s AND parent.%s
$res = $this->dbcon->query($query);
if($res->num_rows == 0) return data;
while($row = $res->fetch_assoc()){
$query = "ALTER TABLE %s DROP COLUMN `%s`, DROP COLUMN `%s`";
}catch (Exception $e){return false;}
$query = "ALTER TABLE %s ADD COLUMN `%s` int(11) NULL";
}catch (Exception $e){return false;}
$query = "ALTER TABLE %s ADD UNIQUE (`%s`), ADD UNIQUE (`%s`)";
}catch (Exception $e){return false;}
// Find children of this device
// Dead end. Update RIGHT
while($row = $res->fetch_assoc()){
// No more children. Update RIGHT
|