ODBC Driver for SQL Server

Build 20.0.7587

Discovering Schemas

The following sections show how to obtain schema information.

List Tables and Views

You can use the odbc_tables function to discover what tables and views are available through the driver. This returns results through a resource like a query would.

$stmt = odbc_tables($cnx);
while ($row = odbc_fetch_array($stmt)) {
    echo "Catalog: ", $row["TABLE_CAT"], "\n";
    echo "Schema: ", $row["TABLE_SCHEM"], "\n";
    echo "Table: ", $row["TABLE_NAME"], "\n";
    echo "Type: ", $row["TABLE_TYPE"], "\n";
}

You can use the odbc_columns method to discover what columns are available on a table or view.

$stmt = odbc_columns($cnx);
while ($row = odbc_fetch_array($stmt)) {
    if ($row["TABLE_NAME"] == "Products") {
        echo "Name: ", $row["COLUMN_NAME"], "\n";
        echo "Type: ", $row["DATA_TYPE"], "\n";
        echo "Length: ", $row["COLUMN_SIZE"], "\n";
        echo "Precision: ", $row["DECIMAL_DIGITS"], "\n";
        echo "Nullable: ", $row["IS_NULLABLE"], "\n";
    }
}

Copyright (c) 2020 CData Software, Inc. - All rights reserved.
Build 20.0.7587