King Luy
King Luy

Reputation: 141

Windows Azure MaxSizeInByte Statement

i want to get the current max size of my DB. I have found the statements an checked it out. It works fine in VS2012 SQL Explorer. But when im using php im geting no data.

This is my function:

function getLoad() {
$conn = connect();
$string = 'DATABASEPROPERTYEX ( 'database' , 'MaxSizeInBytes' )';
$stmt = $conn->query($string);
return $stmt->fetchAll(PDO::FETCH_NUM);
}

The problem is that i get an error in fetching the $stmt. Error is:

can not fetchAll(11)

Upvotes: 1

Views: 84

Answers (1)

Fernando Correia
Fernando Correia

Reputation: 22365

This code will print the database edition and max size in GB:

<?php
function get_database_properties($server, $database, $username, $password) {
    try {
        $conn = new PDO ("sqlsrv:server=tcp:{$server}.database.windows.net,1433; Database={$database}", $username, $password);
        $conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
        $conn->setAttribute(constant('PDO::SQLSRV_ATTR_DIRECT_QUERY'), true);
        $query = "SELECT CONVERT(NVARCHAR(128), DATABASEPROPERTYEX ('{$database}', 'Edition')) as 'Edition', " .
                 "CONVERT(DECIMAL,DATABASEPROPERTYEX ('{$database}', 'MaxSizeInBytes'))/1024/1024/1024 AS 'MaxSizeInGB'";
        $stmt = $conn->query($query);
        $row = $stmt->fetch();
        $conn = null;
        return $row;
    }
    catch (Exception $e) {
        die(print_r($e));
    }
}

$db_properties = get_database_properties("yourserver", "yourdatabase", "youruser", "yourpassword");
print("Edition={$db_properties['Edition']} MaxSizeInGB={$db_properties['MaxSizeInGB']}\n");
?>

Upvotes: 1

Related Questions