CREATE TABLE users (id int, pid int, name varchar(100));
INSERT INTO users (id, pid, name)
VALUES
(1, 0, 'Steven Rogers'),
(2, 1, 'Bruce Banner'),
(3, 1, 'Wally West'),
(4, 2, 'Peter Parker'),
(5, 2, 'Jay Garrick'),
(6, 4, 'Barry Allen'),
(7, 4, 'Reed Richards');
SELECT * FROM users;
<?php
Class Database { }
Class Team extends Database {
private $dbConnection;
function __construct($db)
{
$this->dbConnection = $db;
}
public function getDownline($id, $depth=5) {
$stack = array($id);
for($i=1; $i<=$depth; $i++) {
echo $i.PHP_EOL;
// create an array of levels, each holding an array of child ids for that level
$stack[$i] = $this->getChildren($stack[$i-1]);
}
return $stack;
}
public function countLevel($level) {
// expects an array of child ids
settype($level, 'array');
return sizeof($level);
}
private function getChildren($parent_ids = array()) {
var_dump($parent_ids);
$results = array();
$placeholders = str_repeat('?,', count($parent_ids) - 1). '?';
$sql="select id from users where pid in ($placeholders)";
$stmt=$this->dbConnection->prepare($sql);
$stmt->execute(array($parent_ids));
while($row=$stmt->fetch()) {
$results[] = $row->id;
}
return $results;
}
}
$getTeam = new Team($pdo);
$id = 1;
$depth = 2; // get the counts of his downline, only 2 deep.
$downline_array = $getTeam->getDownline($id, $depth=2);
use Carbon\Carbon;
$now = Carbon::now()->format('d/m/Y');
printf("Today is %s\nCurrent PHP version: %s \n\n", $now, phpversion());
$query = "SELECT VERSION() as version;";
// get DB version using PDO
$stmt = $pdo->prepare($query);
$stmt->execute();
$row = $stmt->fetch(PDO::FETCH_ASSOC);
printf('DB version (PDO): %s ' . PHP_EOL, $row['version']);
// Run query using mysqli
$result = $mysqli->query($query);
$version = $result->fetch_object();
printf('DB version (mysqli): %s ' . PHP_EOL, $version->version);
// Select using Laravel
$version = $db::select($query);
printf('DB version (Laravel Query Builder): %s ' . PHP_EOL, $version[0]->version);