コード例 #1
0
ファイル: test-table.php プロジェクト: kehet/php-cli-utils
 public function testDatabaseDumpMysqli()
 {
     $table = new \Cli\Table();
     $db = new \mysqli('localhost', 'H675X16em4', 'XOc1pu3AcAnINA2eKEY4ruRO8i8iXI', 'test');
     if ($db->connect_errno) {
         throw new \Exception("Failed to connect to MySQL: (" . $db->connect_errno . ") " . $db->connect_error);
     }
     if (!($stmt = $db->prepare("SELECT * FROM `table`"))) {
         throw new \Exception("Prepare failed: (" . $db->errno . ") " . $db->error);
     }
     if (!$stmt->execute()) {
         throw new \Exception("Execute failed: (" . $stmt->errno . ") " . $stmt->error);
     }
     $table->importFromMysqli($stmt);
     $this->expectOutputString('+-------------+-------------+-------------+' . "\n" . '| Col 1       | Col 2       | Col 3       |' . "\n" . '+-------------+-------------+-------------+' . "\n" . '| Col 1 Row 1 | Col 2 Row 1 | Col 3 Row 1 |' . "\n" . '| Col 1 Row 2 | Col 2 Row 2 | Col 3 Row 2 |' . "\n" . '| Col 1 Row 3 | Col 2 Row 3 | Col 3 Row 3 |' . "\n" . '+-------------+-------------+-------------+' . "\n");
     $table->show();
     $stmt->close();
 }