本文整理汇总了PHP中Db::getInstance方法的典型用法代码示例。如果您正苦于以下问题:PHP Db::getInstance方法的具体用法?PHP Db::getInstance怎么用?PHP Db::getInstance使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Db
的用法示例。
在下文中一共展示了Db::getInstance方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: init
public function init()
{
if (Tools::getValue('supplier_rewrite')) {
$name_supplier = str_replace('-', '%', Tools::getValue('supplier_rewrite'));
//
// TODO:: need to core update Prestashop code and
// DB for link_rewrite for suppliers
// Should we use the Mysql FullText Index Search ??
//
$sql = 'SELECT sp.`id_supplier`
FROM `' . _DB_PREFIX_ . 'supplier` sp
LEFT JOIN `' . _DB_PREFIX_ . 'supplier_shop` s ON (sp.`id_supplier` = s.`id_supplier`)
WHERE sp.`name` LIKE \'' . $name_supplier . '\'';
if (Shop::isFeatureActive() && Shop::getContext() == Shop::CONTEXT_SHOP) {
$sql .= ' AND s.`id_shop` = ' . (int) Shop::getContextShopID();
}
$id_supplier = Db::getInstance(_PS_USE_SQL_SLAVE_)->getValue($sql);
if ($id_supplier > 0) {
$_GET['id_supplier'] = $id_supplier;
} else {
//TODO: Do we need to send 404?
header('HTTP/1.1 404 Not Found');
header('Status: 404 Not Found');
}
}
parent::init();
}
示例2: __construct
public function __construct()
{
parent::__construct();
$this->db = Db::getInstance();
$this->max_size = 800000;
//每卷800左右
}
示例3: ecotax_tax_application_fix
function ecotax_tax_application_fix()
{
if (!Db::getInstance()->execute('SELECT `ecotax_tax_rate` FROM `' . _DB_PREFIX_ . 'order_detail` LIMIT 1')) {
return Db::getInstance()->execute('ALTER TABLE `' . _DB_PREFIX_ . 'order_detail` ADD `ecotax_tax_rate` DECIMAL(5, 3) NOT NULL AFTER `ecotax`');
}
return true;
}
示例4: get
public function get($limit = 10, $noloadid = 0)
{
global $cookie;
$_content = array();
if (isset($cookie->viewed) && strlen($cookie->viewed) > 0) {
$_content = explode(",", $cookie->viewed);
}
$product_ids = array();
$content_num = count($_content);
if ($content_num > 0) {
$j = 0;
for ($i = $content_num - 1; $i >= 0; $i--) {
if ($_content[$i] != $noloadid) {
$product_ids[] = $_content[$i];
$j++;
}
if ($j >= $limit) {
break;
}
}
} else {
return false;
}
if (count($product_ids) == 0) {
return false;
}
$result = Db::getInstance()->ExecuteS('SELECT p.*,b.name AS brand FROM `' . _DB_PREFIX_ . 'product` p
LEFT JOIN `' . _DB_PREFIX_ . 'brand` b ON b.id_brand=p.id_brand
WHERE id_product IN(' . implode(',', array_map('intval', $product_ids)) . ')');
if (!$result) {
return false;
}
return Product::reLoad($result);
}
示例5: id_currency_country_fix
function id_currency_country_fix()
{
if (!Db::getInstance()->execute('SELECT `id_currency` FROM `' . _DB_PREFIX_ . 'country` LIMIT 1')) {
return Db::getInstance()->execute('ALTER TABLE `' . _DB_PREFIX_ . 'country` ADD `id_currency` INT NOT NULL DEFAULT \'0\' AFTER `id_zone`');
}
return true;
}
示例6: uninstall
function uninstall()
{
if (!parent::uninstall()) {
return false;
}
return Db::getInstance()->Execute('DROP TABLE `' . _DB_PREFIX_ . 'location_coords`');
}
示例7: uninstall
public function uninstall()
{
if (!parent::uninstall() || !Db::getInstance()->execute('DROP TABLE `' . _DB_PREFIX_ . 'favorite_product`')) {
return false;
}
return true;
}
示例8: add_default_restrictions_modules_groups
/**
* 2007-2015 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 3.0)
* that is bundled with this package in the file LICENSE.txt.
* It is also available through the world-wide-web at this URL:
* http://opensource.org/licenses/osl-3.0.php
* If you did not receive a copy of the license and are unable to
* obtain it through the world-wide-web, please send an email
* to license@prestashop.com so we can send you a copy immediately.
*
* DISCLAIMER
*
* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
* versions in the future. If you wish to customize PrestaShop for your
* needs please refer to http://www.prestashop.com for more information.
*
* @author PrestaShop SA <contact@prestashop.com>
* @copyright 2007-2015 PrestaShop SA
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
function add_default_restrictions_modules_groups()
{
$res = true;
// Table module_group had another use in previous versions, we need to clean it up.
$res &= Db::getInstance()->execute('TRUNCATE TABLE `' . _DB_PREFIX_ . 'module_group`');
$groups = Db::getInstance()->executeS('
SELECT `id_group`
FROM `' . _DB_PREFIX_ . 'group`');
$modules = Db::getInstance()->executeS('
SELECT m.*
FROM `' . _DB_PREFIX_ . 'module` m');
$shops = Db::getInstance()->executeS('
SELECT `id_shop`
FROM `' . _DB_PREFIX_ . 'shop`');
foreach ($groups as $group) {
if (!is_array($modules) || !is_array($shops)) {
return false;
} else {
$sql = 'INSERT INTO `' . _DB_PREFIX_ . 'module_group` (`id_module`, `id_shop`, `id_group`) VALUES ';
foreach ($modules as $mod) {
foreach ($shops as $s) {
$sql .= '("' . (int) $mod['id_module'] . '", "' . (int) $s . '", "' . (int) $group['id_group'] . '"),';
}
}
// removing last comma to avoid SQL error
$sql = substr($sql, 0, strlen($sql) - 1);
$res &= Db::getInstance()->execute($sql);
}
}
return $res;
}
示例9: renderView
public function renderView()
{
$badges_feature = new Collection('badge', $this->context->language->id);
$badges_feature->where('type', '=', 'feature');
$badges_feature->orderBy('id_group');
$badges_feature->orderBy('group_position');
$badges_achievement = new Collection('badge', $this->context->language->id);
$badges_achievement->where('type', '=', 'achievement');
$badges_achievement->orderBy('id_group');
$badges_achievement->orderBy('group_position');
$badges_international = new Collection('badge', $this->context->language->id);
$badges_international->where('type', '=', 'international');
$badges_international->orderBy('id_group');
$badges_international->orderBy('group_position');
$groups = array();
$query = new DbQuery();
$query->select('DISTINCT(b.`id_group`), bl.group_name, b.type');
$query->from('badge', 'b');
$query->join('
LEFT JOIN `' . _DB_PREFIX_ . 'badge_lang` bl ON bl.`id_badge` = b.`id_badge`');
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->executeS($query);
foreach ($result as $res) {
$groups['badges_' . $res['type']][$res['id_group']] = $res['group_name'];
}
$badges_type = array('badges_feature' => array('name' => $this->l('Features'), 'badges' => $badges_feature), 'badges_achievement' => array('name' => $this->l('Achievements'), 'badges' => $badges_achievement), 'badges_international' => array('name' => $this->l('International'), 'badges' => $badges_international));
$levels = array(1 => $this->l('1. Beginner'), 2 => $this->l('2. Pro'), 3 => $this->l('3. Expert'), 4 => $this->l('4. Wizard'), 5 => $this->l('5. Guru'), 6 => $this->l('6. Legend'));
$this->tpl_view_vars = array('badges_type' => $badges_type, 'current_level_percent' => (int) Configuration::get('GF_CURRENT_LEVEL_PERCENT'), 'current_level' => (int) Configuration::get('GF_CURRENT_LEVEL'), 'groups' => $groups, 'levels' => $levels);
return parent::renderView();
}
示例10: upgrade_module_1_3_2_11
function upgrade_module_1_3_2_11($object)
{
$themes = Theme::getThemes();
$theme_meta_value = array();
foreach ($object->controllers as $controller) {
$page = 'module-' . $object->name . '-' . $controller;
$result = Db::getInstance()->getValue('SELECT * FROM ' . _DB_PREFIX_ . 'meta WHERE page="' . pSQL($page) . '"');
if ((int) $result > 0) {
continue;
}
$meta = new Meta();
$meta->page = $page;
$meta->configurable = 0;
$meta->save();
if ((int) $meta->id > 0) {
foreach ($themes as $theme) {
$theme_meta_value[] = array('id_theme' => $theme->id, 'id_meta' => $meta->id, 'left_column' => (int) $theme->default_left_column, 'right_column' => (int) $theme->default_right_column);
}
} else {
$object->_errors[] = sprintf(Tools::displayError('Unable to install controller: %s'), $controller);
}
}
if (count($theme_meta_value) > 0) {
return Db::getInstance()->insert('theme_meta', $theme_meta_value);
}
return true;
}
示例11: getOrderTaxes
public function getOrderTaxes($products = false, $slip = false)
{
if (!$products) {
$products = $slip && Validate::isLoadedObject($slip) ? $slip->getProducts() : $this->getProducts();
}
$taxes = array();
$id_order_details = array();
$defTaxName = null;
$defTaxRate = 0;
if (is_array($products) && count($products)) {
foreach ($products as $product) {
array_push($id_order_details, (int) $product['id_order_detail']);
}
}
if (count($id_order_details)) {
$order_taxes = Db::getInstance()->ExecuteS('
SELECT
od.*,
odt.*,
t.`rate`,
tl.`name`
FROM
`' . _DB_PREFIX_ . 'order_detail` od
LEFT JOIN
`' . _DB_PREFIX_ . 'order_detail_tax` odt ON
(
od.`id_order_detail` = odt.`id_order_detail`
)
LEFT JOIN
`' . _DB_PREFIX_ . 'tax` t ON
(
t.`id_tax` = odt.`id_tax`
)
LEFT JOIN
`' . _DB_PREFIX_ . 'tax_lang` tl ON
(
t.`id_tax` = tl.`id_tax` AND
tl.`id_lang` = ' . (int) $this->id_lang . '
)
WHERE odt.`id_order_detail` IN (' . implode(',', $id_order_details) . ')
');
if ($order_taxes && count($order_taxes)) {
foreach ($order_taxes as $order_tax) {
if (!array_key_exists($order_tax['name'], $taxes)) {
$taxes[$order_tax['name']] = array('total' => 0, 'total_net' => 0, 'total_vat' => 0, 'rate' => (double) $order_tax['rate'], 'percentage' => 0);
}
$taxes[$order_tax['name']]['total_net'] += (double) $order_tax['total_price_tax_excl'];
$taxes[$order_tax['name']]['total_vat'] += (double) $order_tax['total_price_tax_incl'];
$taxes[$order_tax['name']]['total'] += $order_tax['total_price_tax_incl'] - (double) $order_tax['total_price_tax_excl'];
}
}
}
if (count($taxes)) {
foreach ($taxes as &$tax) {
$tax['percentage'] = 100 / ($this->total_products_wt / $tax['total_vat']);
}
return $taxes;
}
return false;
}
示例12: p1540_add_missing_columns
function p1540_add_missing_columns()
{
$errors = array();
$id_module = Db::getInstance()->getValue('SELECT id_module FROM `' . _DB_PREFIX_ . 'module` WHERE name LIKE "loyalty"');
if ($id_module) {
$list_fields = Db::getInstance()->executeS('SHOW FIELDS FROM `' . _DB_PREFIX_ . 'loyalty`');
foreach ($list_fields as $k => $field) {
$list_fields[$k] = $field['Field'];
}
if (in_array('id_discount', $list_fields)) {
if (!Db::getInstance()->execute('ALTER TABLE `' . _DB_PREFIX_ . 'loyalty` CHANGE `id_discount` `id_cart_rule` INT( 10 ) UNSIGNED NULL DEFAULT NULL')) {
$errors[] = Db::getInstance()->getMsgError();
}
}
}
$id_module = Db::getInstance()->getValue('SELECT id_module FROM `' . _DB_PREFIX_ . 'module` WHERE name LIKE "blocklayered"');
if ($id_module) {
$list_fields = Db::getInstance()->executeS('SHOW FIELDS FROM `' . _DB_PREFIX_ . 'layered_product_attribute`');
foreach ($list_fields as $k => $field) {
$list_fields[$k] = $field['Field'];
}
if (!in_array('id_shop', $list_fields)) {
if (!Db::getInstance()->execute('ALTER TABLE `' . _DB_PREFIX_ . 'layered_product_attribute` ADD `id_shop` INT( 10 ) UNSIGNED NOT NULL DEFAULT "1" AFTER `id_attribute_group` ')) {
$errors[] = Db::getInstance()->getMsgError();
}
}
}
if (count($errors)) {
return array('error' => 1, 'msg' => implode(',', $errors));
}
}
示例13: getOrigins
private function getOrigins($dateBetween)
{
$directLink = $this->l('Direct link');
$sql = 'SELECT http_referer
FROM ' . _DB_PREFIX_ . 'connections
WHERE 1
' . Shop::addSqlRestriction() . '
AND date_add BETWEEN ' . $dateBetween;
$result = Db::getInstance(_PS_USE_SQL_SLAVE_)->query($sql);
$websites = array($directLink => 0);
while ($row = Db::getInstance(_PS_USE_SQL_SLAVE_)->nextRow($result)) {
if (!isset($row['http_referer']) || empty($row['http_referer'])) {
++$websites[$directLink];
} else {
$website = preg_replace('/^www./', '', parse_url($row['http_referer'], PHP_URL_HOST));
if (!isset($websites[$website])) {
$websites[$website] = 1;
} else {
++$websites[$website];
}
}
}
arsort($websites);
return $websites;
}
示例14: ps1604_update_employee_date
function ps1604_update_employee_date()
{
if (defined('_PS_CREATION_DATE_')) {
return Db::getInstance()->execute('UPDATE `' . _DB_PREFIX_ . 'employee` SET stats_date_from = \'' . addslashes(_PS_CREATION_DATE_) . '\' WHERE `stats_date_from` < \'' . addslashes(_PS_CREATION_DATE_) . '\'');
}
return true;
}
示例15: getOne
public function getOne()
{
$conn = Db::getInstance();
$advertNumber = $_GET['id'];
$oneAdvert = $conn->query("SELECT * FROM tbl_advert LEFT JOIN tbl_user ON tbl_advert.fk_user_id=tbl_user.user_id WHERE tbl_advert.advert_id={$advertNumber}");
return $oneAdvert;
}