/* * , . * @shopId - * @return false | object PrimaryGoods */ function PrimaryShop($shop = null) { global $primaryshop, $shopId; /* * , * , , * shopId * , , */ if (!isset($shop) && !isset($shopId)) { die(" shopId "); } else { $shopId = isset($shop) ? $shop : $shopId; } if (Database::Setup(Config::Get("primaryDbHost"), Config::Get("primaryDbName"), Config::Get("primaryDbUser"), Config::Get("primaryDbPass"))->Connect()) { return isset($primaryshop) ? $primaryshop : new PrimaryGoods($shopId); } else { die(" "); } } /* * , * @return false | object SecondaryGoods */ function SecondaryShop() { if (Database::Setup(Config::Get("secondaryDbHost"), Config::Get("secondaryDbName"), Config::Get("secondaryDbUser"), Config::Get("secondaryDbPass"))->Connect()) { return new SecondaryGoods(); } else { die(" "); } }
-- SELECT * FROM `data_goods` AS `a` LEFT JOIN `data_goods_price` AS `b` ON `b`.`id` = `a`.`priceId` LEFT JOIN `data_goods_images` AS `c` ON `c`.`id` = `a`.`imagesId` LEFT JOIN `data_goods_attr` AS `d` ON `d`.`id` = `a`.`attrId` -- , SELECT * FROM `data_goods_short`
CREATE TABLE IF NOT EXISTS `data_goods_full` ( `id` int(11) NOT NULL AUTO_INCREMENT, `goodsId` int(11) NOT NULL, `categoryId` int(11) NOT NULL, `shopId` int(11) NOT NULL, `article` varchar(150) NOT NULL, `intro` varchar(255) NOT NULL, `name` varchar(150) NOT NULL, `description` text NOT NULL, PRIMARY KEY (`id`), KEY `categoryId` (`categoryId`), KEY `goodsId` (`goodsId`), KEY `shopId` (`shopId`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8 AUTO_INCREMENT=501 ; CREATE TABLE IF NOT EXISTS `data_goods_images` ( `id` int(11) NOT NULL AUTO_INCREMENT, `goodsId` int(11) NOT NULL, `shopId` int(11) NOT NULL, `type` enum('','','') NOT NULL, `value` varchar(150) NOT NULL, PRIMARY KEY (`id`), KEY `goodsId` (`goodsId`), KEY `shopId` (`shopId`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8; CREATE TABLE IF NOT EXISTS `data_goods_attr` ( `id` int(11) NOT NULL AUTO_INCREMENT, `goodsId` int(11) NOT NULL, `type` enum('','','','') DEFAULT NULL, `value` varchar(150) NOT NULL, PRIMARY KEY (`id`), KEY `goodsId` (`goodsId`) ) ENGINE=MyISAM DEFAULT CHARSET=utf8;
SELECT * FROM `data_goods_full` AS `a` LEFT JOIN `data_goods_images` AS `b` ON `b`.`goodsId` = `a`.`goodsId` LEFT JOIN `data_goods_attr` AS `c` ON `c`.`goodsId` = `a`.`goodsId`
SELECT * FROM `data_goods_images` WHERE `type` = '' AND `goodsId` = '100'
ALTER TABLE `data_goods_attr` CHANGE `type` `type` ENUM('','','','',' ',' ',' , ')
-- INSERT INTO `data_goods_full` (`id`, `goodsId`, `categoryId`, `shopId`, `article`, `intro`, `name`, `description`) VALUES (null, '100', '1', '1', '-100', ' ', ' ', ''); -- INSERT INTO `data_goods_images` (`id`, `goodsId`, `shopId`, `type`, `value`) VALUES (null, '100', '1', '1', '', 'small_a.png'), (null, '100', '1', '1', '', 'big_a.png'); -- INSERT INTO `data_goods_attr` (`id`, `goodsId`, `shopId`, `type`, `value`) VALUES (null, '100', '1', '1', '', 'XL'), (null, '100', '1', '1', '', ''), (null, '100', '1', '1', ' ', '100 .'), (null, '100', '1', '1', ' ', '125 .'); -- , -- INSERT INTO `data_goods_full` (`id`, `goodsId`, `categoryId`, `shopId`, `article`, `intro`, `name`, `description`) VALUES (null, '101', '1', '1', '-101', ' ', ' ', ''); -- INSERT INTO `data_goods_images` (`id`, `goodsId`, `shopId`, `type`, `value`) VALUES (null, '101', '1', '1', '', 'midle_b.png'), (null, '101', '1', '1', '', 'big_b.png'); -- INSERT INTO `data_goods_attr` (`id`, `goodsId`, `shopId`, `type`, `value`) VALUES (null, '101', '1', '1', ' ', '125 .'), (null, '101', '1', '1', ' , ', '120 .');
Array ( [property] => stdClass Object ( [id] => 1 [categoryId] => 1 [article] => -100 [intro] => [name] => [text] => ) [images] => Array ( [0] => stdClass Object ( [imageType] => [imageValue] => small_a.png ) [1] => stdClass Object ( [imageType] => [imageValue] => big_a.png ) ) [attributes] => Array ( [0] => stdClass Object ( [attrType] => [attrValue] => XL ) [1] => stdClass Object ( [attrType] => [attrValue] => ) [2] => stdClass Object ( [attrType] => [attrValue] => 100 . ) [3] => stdClass Object ( [attrType] => [attrValue] => 125 . ) ) ) Array ( [property] => stdClass Object ( [id] => 2 [categoryId] => 1 [article] => -101 [intro] => [name] => [text] => ) [images] => Array ( [0] => stdClass Object ( [imageType] => [imageValue] => midle_b.png ) [1] => stdClass Object ( [imageType] => [imageValue] => big_b.png ) ) [attributes] => Array ( [0] => stdClass Object ( [attrType] => [attrValue] => 125 . ) [1] => stdClass Object ( [attrType] => , [attrValue] => 120 . ) ) )
/* * , * type images */ function GetImagesSet() { $query = "\n DESCRIBE `data_goods_images` `type`"; if ($result = Database::Exec($query)->Read(0, "Type")) { $result = str_replace(array("enum", "(", ")", "'"), array("", "", "", ""), $result); return $result ? explode(",", $result) : $result; } } /* * . * , .. .. */ function AddImagesSet($type = null) { if (isset($type)) { $result = $this->GetImagesSet(); if (!empty($result)) { foreach ($result as $item) { $enum[] = "'".$item."'"; } $enum = implode(",", $enum).","; } else { $enum = ""; } $enum = $enum.str_replace(" ", "", $type); $query = "\n ALTER TABLE `d ata_goods_images` CHANGE `type` `type` ENUM(".$enum.")"; return Database::Exec($query)->Read(); } else { return false; } } /* * . * @example: '', '', '' DelImagesSet('') => '', '' * @return true | flase */ function DelImagesSet($type = null) { if (isset($type)) { foreach(self::GetImagesSet() as $value) { if ($type != $value) { $enum[] = "'".$value."'"; } } $query = "\n ALTER TABLE `data_goods_images` CHANGE `type` `type` ENUM(".implode(",", $enum).")"; return Database::Exec($query)->Read(); } else { return false; } }
Source: https://habr.com/ru/post/137503/
All Articles