PHP code example of maba / database-inconsistency-finder
1. Go to this page and download the library: Download maba/database-inconsistency-finder library. Choose the download type require. 2. Extract the ZIP file and open the index.php. 3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
maba / database-inconsistency-finder example snippets
$connection = DriverManager::getConnection(['url' => 'mysql://user:secret@localhost/mydb']);
$connection1 = DriverManager::getConnection(['url' => 'mysql://user:[email protected]/otherdb']);
$referencesConfiguration = (new ReferencesConfiguration())
->setReferencedColumn(
(new ReferencedColumn())
->setConnection($connection)
->setTableName('files')
->setIdColumnName('id')
->setReferenceNumberColumnName('reference_count')
)
->addTableReferences(
(new TableReferences())
->setConnection($connection)
->setTableName('profiles')
->setColumnNames(['avatar_file_id', 'cv_file_id'])
)
->addTableReferences(
(new TableReferences())
->setConnection($connection1)
->setTableName('documents')
->setColumnNames(['file_id'])
)
;
$inconsistencyFinder = (new Factory())
->createInconsistencyFinder($referencesConfiguration)
;
$result = $inconsistencyFinder->find();
if ($result->areInconsistenciesFound()) {
var_dump(
$result->getOrphanedRecordIds(),
$result->getMissingReferenceCounts(),
$result->getInvalidReferenceCounts()
);
}