test22222
$(document).ready(function () {
alert('RUNOOB');
});function checkField() {
$db = Typecho_Db::get();
$prefix = $db->getPrefix();
// Determine the database adapter
$adapter = $db->getAdapterName();
// Get the columns info depending on adapter
if ($adapter === 'Pdo_Sqlite') {
// SQLite syntax
$postFields = $db->fetchAll($db->query('PRAGMA table_info(' . $prefix . 'contents)'));
$columnNames = array_column($postFields, 'name');
} else {
// MySQL syntax
$postFields = $db->fetchAll($db->query("SHOW COLUMNS FROM `" . $prefix . "contents`"));
$columnNames = array_column($postFields, 'Field');
}
// If 'views' column does not exist, add it
if (!in_array('views', $columnNames)) {
$db->query('ALTER TABLE `' . $prefix . 'contents` ADD `views` INT(10) NOT NULL DEFAULT 0;');
}
// If 'agree' column does not exist, add it
if (!in_array('agree', $columnNames)) {
$db->query('ALTER TABLE `' . $prefix . 'contents` ADD `agree` INT(10) NOT NULL DEFAULT 0;');
}
}
if ($db->getAdapterName() === 'Pdo_Sqlite') {
$result = $db->query('PRAGMA table_info(typecho_contents)');
} else {
// MySQL syntax to get columns info
$result = $db->query("SHOW COLUMNS FROM `typecho_contents`");
} Copyright Notice: This article is an original work. Copyright belongs to Will's Blog. Please contact the author for permission before reprinting.
Article URL: https://loopback0.1amwill.com/archives/4/
If you have any questions or concerns about this article, feel free to leave a comment. I will try my best to respond as soon as possible.
test1111