forked from GithubBackups/tinyib
Add postgresql support
(cherry picked from commit b5ccfe321086eb5935180e5e93b08afcbf6a78eb)
This commit is contained in:
parent
013de06804
commit
2a41e2f8e4
@ -13,9 +13,14 @@ if (TINYIB_DBDSN == '') { // Build a default (likely MySQL) DSN
|
|||||||
$dsn = TINYIB_DBDSN;
|
$dsn = TINYIB_DBDSN;
|
||||||
}
|
}
|
||||||
|
|
||||||
$options = array(PDO::ATTR_PERSISTENT => true,
|
if (TINYIB_DBDRIVER === 'pgsql') {
|
||||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
$options = array(PDO::ATTR_PERSISTENT => true,
|
||||||
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8');
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION);
|
||||||
|
} else {
|
||||||
|
$options = array(PDO::ATTR_PERSISTENT => true,
|
||||||
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||||
|
PDO::MYSQL_ATTR_INIT_COMMAND => 'SET NAMES utf8');
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
$dbh = new PDO($dsn, TINYIB_DBUSERNAME, TINYIB_DBPASSWORD, $options);
|
$dbh = new PDO($dsn, TINYIB_DBUSERNAME, TINYIB_DBPASSWORD, $options);
|
||||||
@ -24,14 +29,28 @@ try {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Create the posts table if it does not exist
|
// Create the posts table if it does not exist
|
||||||
$dbh->query("SHOW TABLES LIKE " . $dbh->quote(TINYIB_DBPOSTS));
|
if (TINYIB_DBDRIVER === 'pgsql') {
|
||||||
if ($dbh->query("SELECT FOUND_ROWS()")->fetchColumn() == 0) {
|
$query = "SELECT COUNT(*) FROM pg_catalog.pg_tables WHERE tablename LIKE " . $dbh->quote(TINYIB_DBPOSTS);
|
||||||
|
$posts_exists = $dbh->query($query)->fetchColumn() != 0;
|
||||||
|
} else {
|
||||||
|
$dbh->query("SHOW TABLES LIKE " . $dbh->quote(TINYIB_DBPOSTS));
|
||||||
|
$posts_exists = $dbh->query("SELECT FOUND_ROWS()")->fetchColumn() != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$posts_exists) {
|
||||||
$dbh->exec($posts_sql);
|
$dbh->exec($posts_sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Create the bans table if it does not exist
|
// Create the bans table if it does not exist
|
||||||
$dbh->query("SHOW TABLES LIKE " . $dbh->quote(TINYIB_DBBANS));
|
if (TINYIB_DBDRIVER === 'pgsql') {
|
||||||
if ($dbh->query("SELECT FOUND_ROWS()")->fetchColumn() == 0) {
|
$query = "SELECT COUNT(*) FROM pg_catalog.pg_tables WHERE tablename LIKE " . $dbh->quote(TINYIB_DBBANS);
|
||||||
|
$bans_exists = $dbh->query($query)->fetchColumn() != 0;
|
||||||
|
} else {
|
||||||
|
$dbh->query("SHOW TABLES LIKE " . $dbh->quote(TINYIB_DBBANS));
|
||||||
|
$bans_exists = $dbh->query("SELECT FOUND_ROWS()")->fetchColumn() != 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!$bans_exists) {
|
||||||
$dbh->exec($bans_sql);
|
$dbh->exec($bans_sql);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -3,47 +3,91 @@ if (!defined('TINYIB_BOARD')) {
|
|||||||
die('');
|
die('');
|
||||||
}
|
}
|
||||||
|
|
||||||
$posts_sql = "CREATE TABLE `" . TINYIB_DBPOSTS . "` (
|
if (TINYIB_DBDRIVER === 'pgsql') {
|
||||||
`id` mediumint(7) unsigned NOT NULL auto_increment,
|
$posts_sql = 'CREATE TABLE "' . TINYIB_DBPOSTS . '" (
|
||||||
`parent` mediumint(7) unsigned NOT NULL,
|
"id" bigserial NOT NULL,
|
||||||
`timestamp` int(20) NOT NULL,
|
"parent" integer NOT NULL,
|
||||||
`bumped` int(20) NOT NULL,
|
"timestamp" integer NOT NULL,
|
||||||
`ip` varchar(39) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
"bumped" integer NOT NULL,
|
||||||
`name` varchar(75) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
"ip" varchar(39) NOT NULL,
|
||||||
`tripcode` varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
"name" varchar(75) NOT NULL,
|
||||||
`email` varchar(75) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
"tripcode" varchar(10) NOT NULL,
|
||||||
`nameblock` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
"email" varchar(75) NOT NULL,
|
||||||
`subject` varchar(75) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
"nameblock" varchar(255) NOT NULL,
|
||||||
`message` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
"subject" varchar(75) NOT NULL,
|
||||||
`password` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
"message" text NOT NULL,
|
||||||
`file` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
"password" varchar(255) NOT NULL,
|
||||||
`file_hex` varchar(75) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
"file" text NOT NULL,
|
||||||
`file_original` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
"file_hex" varchar(75) NOT NULL,
|
||||||
`file_size` int(20) unsigned NOT NULL default '0',
|
"file_original" varchar(255) NOT NULL,
|
||||||
`file_size_formatted` varchar(75) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
"file_size" integer NOT NULL default \'0\',
|
||||||
`image_width` smallint(5) unsigned NOT NULL default '0',
|
"file_size_formatted" varchar(75) NOT NULL,
|
||||||
`image_height` smallint(5) unsigned NOT NULL default '0',
|
"image_width" smallint NOT NULL default \'0\',
|
||||||
`thumb` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
"image_height" smallint NOT NULL default \'0\',
|
||||||
`thumb_width` smallint(5) unsigned NOT NULL default '0',
|
"thumb" varchar(255) NOT NULL,
|
||||||
`thumb_height` smallint(5) unsigned NOT NULL default '0',
|
"thumb_width" smallint NOT NULL default \'0\',
|
||||||
`stickied` tinyint(1) NOT NULL default '0',
|
"thumb_height" smallint NOT NULL default \'0\',
|
||||||
`moderated` tinyint(1) NOT NULL default '1',
|
"stickied" smallint NOT NULL default \'0\',
|
||||||
PRIMARY KEY (`id`),
|
"moderated" smallint NOT NULL default \'1\',
|
||||||
KEY `parent` (`parent`),
|
PRIMARY KEY ("id")
|
||||||
KEY `bumped` (`bumped`),
|
);
|
||||||
KEY `stickied` (`stickied`),
|
CREATE INDEX ON "' . TINYIB_DBPOSTS . '"("parent");
|
||||||
KEY `moderated` (`moderated`)
|
CREATE INDEX ON "' . TINYIB_DBPOSTS . '"("bumped");
|
||||||
)";
|
CREATE INDEX ON "' . TINYIB_DBPOSTS . '"("stickied");
|
||||||
|
CREATE INDEX ON "' . TINYIB_DBPOSTS . '"("moderated");';
|
||||||
|
|
||||||
$bans_sql = "CREATE TABLE `" . TINYIB_DBBANS . "` (
|
$bans_sql = 'CREATE TABLE "' . TINYIB_DBBANS . '" (
|
||||||
`id` mediumint(7) unsigned NOT NULL auto_increment,
|
"id" bigserial NOT NULL,
|
||||||
`ip` varchar(39) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
"ip" varchar(39) NOT NULL,
|
||||||
`timestamp` int(20) NOT NULL,
|
"timestamp" integer NOT NULL,
|
||||||
`expire` int(20) NOT NULL,
|
"expire" integer NOT NULL,
|
||||||
`reason` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
"reason" text NOT NULL,
|
||||||
PRIMARY KEY (`id`),
|
PRIMARY KEY ("id")
|
||||||
KEY `ip` (`ip`)
|
);
|
||||||
)";
|
CREATE INDEX ON "' . TINYIB_DBBANS . '"("ip");';
|
||||||
|
} else {
|
||||||
|
$posts_sql = "CREATE TABLE `" . TINYIB_DBPOSTS . "` (
|
||||||
|
`id` mediumint(7) unsigned NOT NULL auto_increment,
|
||||||
|
`parent` mediumint(7) unsigned NOT NULL,
|
||||||
|
`timestamp` int(20) NOT NULL,
|
||||||
|
`bumped` int(20) NOT NULL,
|
||||||
|
`ip` varchar(39) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
||||||
|
`name` varchar(75) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
||||||
|
`tripcode` varchar(10) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
||||||
|
`email` varchar(75) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
||||||
|
`nameblock` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
||||||
|
`subject` varchar(75) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
||||||
|
`message` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
||||||
|
`password` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
||||||
|
`file` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
||||||
|
`file_hex` varchar(75) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
||||||
|
`file_original` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
||||||
|
`file_size` int(20) unsigned NOT NULL default '0',
|
||||||
|
`file_size_formatted` varchar(75) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
||||||
|
`image_width` smallint(5) unsigned NOT NULL default '0',
|
||||||
|
`image_height` smallint(5) unsigned NOT NULL default '0',
|
||||||
|
`thumb` varchar(255) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
||||||
|
`thumb_width` smallint(5) unsigned NOT NULL default '0',
|
||||||
|
`thumb_height` smallint(5) unsigned NOT NULL default '0',
|
||||||
|
`stickied` tinyint(1) NOT NULL default '0',
|
||||||
|
`moderated` tinyint(1) NOT NULL default '1',
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
KEY `parent` (`parent`),
|
||||||
|
KEY `bumped` (`bumped`),
|
||||||
|
KEY `stickied` (`stickied`),
|
||||||
|
KEY `moderated` (`moderated`)
|
||||||
|
)";
|
||||||
|
|
||||||
|
$bans_sql = "CREATE TABLE `" . TINYIB_DBBANS . "` (
|
||||||
|
`id` mediumint(7) unsigned NOT NULL auto_increment,
|
||||||
|
`ip` varchar(39) CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
||||||
|
`timestamp` int(20) NOT NULL,
|
||||||
|
`expire` int(20) NOT NULL,
|
||||||
|
`reason` text CHARACTER SET utf8 COLLATE utf8_unicode_ci NOT NULL,
|
||||||
|
PRIMARY KEY (`id`),
|
||||||
|
KEY `ip` (`ip`)
|
||||||
|
)";
|
||||||
|
}
|
||||||
|
|
||||||
function cleanString($string) {
|
function cleanString($string) {
|
||||||
$search = array("<", ">");
|
$search = array("<", ">");
|
||||||
|
Loading…
x
Reference in New Issue
Block a user