How to List SQL .BAK Backup Tables in PHP
Creating SQL .BAK files is common practice to preserve a given state of a SQL database in case of data corruption/data loss. Using the API solution provided in this article, you can easily retrieve all the tables in any given .BAK file with a single request and list them in JSON format. Your response will be structured based on the following example:
{
"successful": true,
"tables": [
{
"schemaName": "string",
"tableName": "string"
}
]
}
In this article, I’ve provided ready-to-run PHP code examples which you can use to easily structure your API call. If you’re looking for different code examples, you can find a broader selection here.
We can start client SDK installation by running the following command from our command line:
composer require cloudmersive/cloudmersive_dataintegration_api_client
After that, we can use the below PHP examples to structure our API call. In our request, we’ll need to include our .BAK files along with an API key for request authorization (visit our website and register a free account to get a free-tier API key with 800 API calls per month):
<?php
require_once(__DIR__ . '/vendor/autoload.php');
// Configure API key authorization: Apikey
$config = Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Apikey', 'YOUR_API_KEY');
$apiInstance = new Swagger\Client\Api\BackupConvertApi(
new GuzzleHttp\Client(),
$config
);
$input_file = "/path/to/inputfile"; // \SplFileObject | Input file to perform the operation on
try {
$result = $apiInstance->dataintegrationBackupConvertMssqlBakGetTablesPost($input_file);
print_r($result);
} catch (Exception $e) {
echo 'Exception when calling BackupConvertApi->dataintegrationBackupConvertMssqlBakGetTablesPost: ', $e->getMessage(), PHP_EOL;
}
?>
That’s all you need to do — no more code required!