Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
random sql stuff
<?php
$db1 = new PDO('mysql:host=localhost;dbname=insertbooking', 'root', '', array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
$db1->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db1->setAttribute(PDO::ATTR_ORACLE_NULLS, PDO::NULL_EMPTY_STRING);
$db2 = new PDO('mysql:host=localhost;dbname=testdb', 'root', '', array(PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES utf8"));
$db2->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db2->setAttribute(PDO::ATTR_ORACLE_NULLS, PDO::NULL_EMPTY_STRING);
$sql = 'SELECT * FROM info';
$queryDB1 = $db1->prepare($sql);
$queryDB1->execute();
$dataDb1 = $queryDB1->fetchAll(PDO::FETCH_ASSOC);
$queryDB2 = $db2->prepare($sql);
$queryDB2->execute();
$dataDB2 = $queryDB2->fetchAll(PDO::FETCH_ASSOC);
foreach ($dataDB1 as $key => $row1) {
if (!isset($dataDB2[$key]) || !isset($dataDB1[$key])) {
// Data does not exist on test table table
continue;
}
if ($dataDB1[$key] == $dataDB2[$key]) {
echo "ID: " . $dataDB1[$key]['id'] . " is equal " . PHP_EOL;
continue;
}
echo "ID: " . $dataDB1[$key]['id'] . " not equal " . PHP_EOL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment