"emp.id != B.manager" ) ) )'); $sql_queries = array('SELECT * FROM emp', 'SELECT * FROM deptloc', 'SELECT * FROM location', 'SELECT * FROM dept', 'SELECT * FROM account', 'SELECT * FROM nothere WHERE pigs = "fly"', 'SELECT * FROM emp WHERE salary >= 1500', 'SELECT * from emp WHERE (job <> "analyst") AND (job <> "intern") ORDER BY empname', 'SELECT * from emp WHERE (job <> "analyst") AND (job <> "intern") ORDER BY empname DESC', 'SELECT empname, deptname, deptno FROM emp, dept WHERE emp.deptno = dept.deptno', 'SELECT * FROM location, dept, deptloc WHERE dept.deptno = deptloc.deptno AND location.locno = deptloc.locno', 'SELECT * FROM location, dept, deptloc WHERE dept.deptno = deptloc.deptno AND location.locno = deptloc.locno ORDER BY manager', 'SELECT empname, locname, deptname FROM location, dept, deptloc, emp WHERE dept.deptno = deptloc.deptno AND location.locno = deptloc.locno AND emp.id <> dept.manager ORDER BY empname, locname, deptname'); foreach ($queries as $key => $query) { echo "Query:\n{$query}\n\n"; echo "SQL equivalent:\n{$sql_queries[$key]}\n\n"; eval('$results = ' . $query . ';'); if (PEAR::isError($results)) { echo " Query failed.\n"; echo $results->getMessage() . "\n"; } else { echo "Results:\n"; echo formatTextTable($results); } echo "\n************************************************\n\n"; } // $db->close();
// open and close table multiple times while inserting //foreach (array('w','r') as $mode) { $mode = 'w'; $result = $table->open('hats', $mode); if (PEAR::isError($result)) { echo $result->getMessage() . "\n"; exit; } echo "Created table 'hats'\n"; for ($i = 0; $i < 2; ++$i) { foreach ($hats as $hat) { $result = $table->insert($hat); if (PEAR::isError($result)) { echo 'Could not insert: ' . $result->getMessage() . "\n"; } } } $queries = array('$table->select("(type != bowler) and (type != fedora)")', '$table->select("quantity<=60")', '$table->select("quantity>=50")', '$table->sort("quantity, hat_id", "a", $table->select("*"))', '$table->sort(array("quantity", "hat_id"), "a", $table->getRows())', '$table->sort("lastshipment", "d", $table->select("*"))', '$table->unique($table->project("brand,quantity, type",$table->sort("quantity", "d", $table->select("type != \'top hat\'"))))', '$table->remove("type == bowler")', '$table->project("brand, type", $table->select("*"))'); foreach ($queries as $query) { echo "Query: {$query}\n"; eval('$results = ' . $query . ';'); if (PEAR::isError($results)) { echo " Query failed.\n"; echo $results->getMessage() . "\n"; } else { echo formatTextTable($table->finalize($results), null, 'mysql'); } echo "------------------------------------------------\n\n"; } $table->close(); //}