"; } if(parent::key() == "alt"){ return "

".parent::current()."

"; } return ""; } function beginChildren() { echo "
"; } function endChildren() { echo "
" . "\n"; } } $servername = "localhost"; $username = "username"; $password = "password"; $dbname = "phpdemo"; try { $conn = new PDO("mysql:host=$servername;dbname=$dbname", $username, $password); $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION); $stmt = $conn->prepare("SELECT id, url, alt FROM images"); $stmt->execute(); // set the resulting array to associative $result = $stmt->setFetchMode(PDO::FETCH_ASSOC); foreach(new TableRows(new RecursiveArrayIterator($stmt->fetchAll())) as $k=>$v) { echo $v; } } catch(PDOException $e) { echo "Error: " . $e->getMessage(); } $conn = null; ?>