(I apologize in advance if this questions is posted in an improper or non-optimal venue.)
I am trying to compare the version number of the database schema from the table below with that of $oc_db_version from version.php.
DROP TABLE IF EXISTS `oc_config`;
CREATE TABLE `oc_config` (
`key` varchar(80) NOT NULL,
`value` varchar(80) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=COMPACT;
INSERT INTO `oc_config` (`key`, `value`) VALUES
('api_key', 'pzPgYOO7vz1WxgfD5913BMp5RYX8wpZPdp2KN5pdx78MRscT2X65zrmgfBQXCpQG'),
('oc_db_version', '999');
I can't seem to get it working. I either get something to the effect of "PDOStatement cannot be converted to int" or I get bool(true). Below it the code which I am currently using.
try{
$pdo = new PDO('mysql:host='.DB_HOST.';dbname='.DB_NAME, DB_USER, DB_PASSWORD);
} catch(PDOException $ex)
{
$_SESSION['error'] = "Could not connect -> ".$ex->getMessage();
$_SESSION['error_blob'] = $ex;
header('Location: '.BASE_URL.'/oc-content/plugins/error/index.php');
die();
}
$stmt = $pdo->query("SELECT value FROM ".DB_PREFIX."config WHERE `key` = 'oc_db_version'");
$result = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$result['value'])
{
header('Location: '.BASE_URL.'/oc-content/plugins/error/index.php');
die();
}
if ( $result['value'] != $oc_db_version || $result['value'] > $oc_db_version )
{
die("Database version mimatch. Please upgrade.");
}
else{
// Do Nothing
};
$pdo = null;
I realize the code above could do with refactoring, some are probably cringing reading it and for that I apologize. I'd just like to get it working.