MySQL::GetTables PHP Method

GetTables() public method

This function returns table names from the database into an array. If the database does not contains any tables, the returned value is FALSE
public GetTables ( ) : array
return array An array that contains the table names
    public function GetTables()
    {
        $this->ResetError();
        // Query to get the tables in the current database:
        $records = mysqli_query($this->mysql_link, "SHOW TABLES");
        if (!$records) {
            $this->SetError();
            return FALSE;
        } else {
            while ($array_data = mysqli_fetch_array($records)) {
                $tables[] = $array_data[0];
            }
            // Returns the array or NULL
            if (count($tables) > 0) {
                return $tables;
            } else {
                return FALSE;
            }
        }
    }

Usage Example

コード例 #1
0
ファイル: example.php プロジェクト: kimai/kimai
}
// --- Loop through the records another way -------------------------
$db->MoveFirst();
while (!$db->EndOfSeek()) {
    $row = $db->Row();
    echo $row->Color . " - " . $row->Age . "<br />\n";
}
// --- Loop through the records with an index -----------------------
for ($index = 0; $index < $db->RowCount(); $index++) {
    $row = $db->Row($index);
    echo "Row " . $index . ":" . $row->Color . " - " . $row->Age . "<br />\n";
}
// --- We can even grab array data from the last result set ---------
$myArray = $db->RecordsArray();
// --- List all of the tables in the database -----------------------
$tables = $db->GetTables();
foreach ($tables as $table) {
    echo $table . "<br />\n";
}
// --- Show the columns (field names) in a table --------------------
$columns = $db->GetColumnNames("test");
foreach ($columns as $column) {
    echo $column . "<br />\n";
}
// --- Find a column (field) type and length ------------------------
echo "Type: " . $db->GetColumnDataType("Color", "Test") . "<br />\n";
echo "Length: " . $db->GetColumnLength("Color", "Test") . "<br />\n";
// --- Get a column's ordinal position (the column number) ----------
echo $db->GetColumnID("Age", "Test") . "<br />\n";
// --- Check for errors ---------------------------------------------
if ($db->Error()) {