fetchColumn example

protected function isLayerResponsible(?int $shopId): bool
    {
        $queryBuilder = $this->connection->createQueryBuilder();

        return $queryBuilder->select('1')
                ->from('s_core_shops')
                ->andWhere($queryBuilder->expr()->eq('id', ':id'))
                ->andWhere($queryBuilder->expr()->isNull('main_id'))
                ->andWhere($queryBuilder->expr()->lt('`default`', 1))
                ->setParameter('id', $shopId)
                ->execute()->fetchColumn() !== false
        ;
    }
}
->prepare('SELECT * FROM s_categories WHERE id = :id');
        $originalCategoryStmt->execute([':id' => $originalCategoryId]);
        $originalCategory = $originalCategoryStmt->fetch(PDO::FETCH_ASSOC);

        if (empty($originalCategory)) {
            throw new RuntimeException(sprintf('Category "%s" not found', $originalCategoryId));
        }

        $newPosStmt = $this->connection
            ->prepare('SELECT MAX(`position`) FROM s_categories WHERE parent = :parent');
        $newPosStmt->execute([':parent' => $parentId]);
        $newPos = (int) $newPosStmt->fetchColumn();
        $originalCategory['position'] = $newPos + 1;

        $originalCategory['parent'] = $parentId;

        unset($originalCategory['id']$originalCategory['path']);

        $valuePlaceholders = array_fill(0, \count($originalCategory), '?');
        $insertStmt = $this->connection->prepare(
            'INSERT INTO s_categories (`' . implode('`, `', array_keys($originalCategory)) . '`) VALUES (' . implode(', ', $valuePlaceholders) . ')'
        );
        

    private function getInstalledLicense()
    {
        $sql = 'SELECT license FROM s_core_licenses WHERE active=1 AND module = "SwagCommercial"';

        return $this->container->get(Connection::class)->query($sql)->fetchColumn();
    }

    /** * Checks a license key string and on error deletes * currently installed core licenses if $deleteOnError = true. * Returns LicenseInformation on success. * * @param string $licenseString * * @throws RuntimeException * * @return LicenseInformation */
class Migrations_Migration1204 extends Shopware\Components\Migrations\AbstractMigration
{
    public function up($modus)
    {
        $sql = <<<SQL INSERT IGNORE INTO `s_search_custom_facet` (`id`, `unique_key`, `active`, `display_in_categories`, `position`, `name`, `facet`, `deletable`) VALUES (NULL, 'VariantFacet', 0, 1, 11, 'Varianten', '{"Shopware\\\\\\\Bundle\\\\\\\SearchBundle\\\\\\\Facet\\\\\\\VariantFacet":{"groupIds":"", "expandGroupIds":""}}', 0) ; SQL;
        $this->addSql($sql);

        $id = (int) $this->connection->query('SELECT id FROM `s_search_custom_facet` WHERE `unique_key` = "VariantFacet"')->fetchColumn(0);

        $this->importFacetTranslations($id);
    }

    /** * @param int $facetId */
    private function importFacetTranslations($facetId)
    {
        $shops = $this->connection->query('SELECT shops.id, shops.main_id, shops.locale_id, locales.locale FROM s_core_shops shops INNER JOIN s_core_locales locales ON locales.id=shops.locale_id')
            ->fetchAll(PDO::FETCH_ASSOC);

        
        $this->getInternalStore()->save($key);

        $lockAcquired = false;

        try {
            $sql = 'SELECT pg_try_advisory_lock(:key)';
            $stmt = $this->getConnection()->prepare($sql);
            $stmt->bindValue(':key', $this->getHashedKey($key));
            $result = $stmt->execute();

            // Check if lock is acquired             if (true === $stmt->fetchColumn()) {
                $key->markUnserializable();
                // release sharedLock in case of promotion                 $this->unlockShared($key);

                $lockAcquired = true;

                return;
            }
        } finally {
            if (!$lockAcquired) {
                $this->getInternalStore()->delete($key);
            }


    public function confirmValidationAction()
    {
        $connection = $this->container->get(Connection::class);

        $modelManager = $this->container->get(ModelManager::class);

        $hash = $this->Request()->get('sConfirmation');

        $sql = "SELECT `data` FROM `s_core_optin` WHERE `hash` = ? AND type = 'swRegister'";
        $result = $connection->fetchColumn($sql[$hash]);

        // Triggers an Error-Message, which tells the customer that his confirmation link was invalid         if (empty($result)) {
            $this->redirectCustomer([
                'optinhashinvalid' => true,
            ]);

            return;
        }

        try {
            
public function __construct(Connection $connection)
    {
        $this->connection = $connection;
    }

    /** * {@inheritdoc} */
    public function hasCustomerStreamEmotions($categoryId)
    {
        return $this->connection->fetchColumn(
            'SELECT emotion.id FROM s_emotion emotion INNER JOIN s_emotion_categories categories ON categories.emotion_id = emotion.id AND categories.category_id = :id WHERE emotion.customer_stream_ids IS NOT NULL AND emotion.active = 1 LIMIT 1',
            [':id' => $categoryId]
        );
    }

    


    protected function isLayerResponsible(?int $shopId): bool
    {
        $queryBuilder = $this->connection->createQueryBuilder();

        return $queryBuilder->from('s_core_shops')
            ->select('1')
            ->andWhere($queryBuilder->expr()->eq('id', ':id'))
            ->andWhere($queryBuilder->expr()->isNotNull('main_id'))
            ->setParameter('id', $shopId)
            ->execute()->fetchColumn() !== false
        ;
    }
}
try {
            $query = $db->prepare($sql);
            $query->bindParam('field', $field, PDO::PARAM_STR);
            $query->bindParam('direction', $direction, PDO::PARAM_STR);
            $query->bindParam('limit', $limit, PDO::PARAM_INT);
            $query->bindParam('offset', $offset, PDO::PARAM_INT);
            $query->execute();

            $this->View()->assign([
                'success' => true,
                'data' => $query->fetchAll(PDO::FETCH_ASSOC),
                'total' => $db->fetchColumn('SELECT FOUND_ROWS()'),
            ]);
        } catch (DBALException $exception) {
            $this->View()->assign([
                'success' => false,
                'message' => $exception->getMessage(),
            ]);
        }
    }

    /** * Updates an existing recipient, e.g. to change it's group */
return 0;
    }

    /** * @return int */
    private function getResponsiveTemplateId()
    {
        $statement = $this->conn->query('SELECT id FROM s_core_templates WHERE template LIKE "Responsive"');
        $statement->execute();
        $templateId = $statement->fetchColumn();

        if (!$templateId) {
            throw new RuntimeException('Could not get id for default template');
        }

        return (int) $templateId;
    }

    /** * @param int $templateId */
    

    }

    /** * {@inheritdoc} */
    public function getCount(Context $context)
    {
        return (int) $this->getBaseQuery()
            ->addSelect(['COUNT(id)'])
            ->execute()
            ->fetchColumn();
    }

    /** * @return QueryBuilder */
    private function getBaseQuery()
    {
        return $this->connection->createQueryBuilder()
            ->from('s_articles_supplier');
    }
}


    /** * Calculated the total count of the whole search result. * * @param QueryBuilder $query * * @return int */
    private function getTotalCount($query)
    {
        return $query->getConnection()->fetchColumn('SELECT FOUND_ROWS()');
    }

    /** * @throws Exception * * @return SearchBundle\FacetResultInterface[] */
    private function createFacets(SearchBundle\Criteria $criteria, ShopContextInterface $context)
    {
        if (\count($criteria->getFacets()) === 0) {
            return [];
        }

        );

        $defaultLocaleIdStatement->execute();
        $defaultLocale = $defaultLocaleIdStatement->fetchColumn();

        $insertStatement = $this->connection->prepare('INSERT INTO `s_core_countries` (`countryname`, `countryiso`, `areaID`, `countryen`, `position`, `notice`, `taxfree`, `taxfree_ustid`, `taxfree_ustid_checked`, `active`, `iso3`, `display_state_in_registration`, `force_state_in_registration`, `allow_shipping`) ' .
            ' VALUES (:countryName, :countryIso, :areaID, :countryEn, 10, "", 0, 0, 0, 0, :iso3, 0, 0, 1)');

        foreach (array_diff($newCountryIsos$currentCountryList) as $missingIso) {
            $newCountry = $newCountries[$missingIso];
            $this->saveNewCountry($insertStatement$newCountry$defaultLocale);
        }
    }

    /** * @param string $defaultLocale */


    public function exists(Key $key): bool
    {
        $sql = "SELECT 1 FROM $this->table WHERE $this->idCol = :id AND $this->tokenCol = :token AND $this->expirationCol > {$this->getCurrentTimestampStatement()}";
        $stmt = $this->getConnection()->prepare($sql);

        $stmt->bindValue(':id', $this->getHashedKey($key));
        $stmt->bindValue(':token', $this->getUniqueToken($key));
        $result = $stmt->execute();

        return (bool) (\is_object($result) ? $result->fetchOne() : $stmt->fetchColumn());
    }

    private function getConnection(): \PDO
    {
        if (!isset($this->conn)) {
            $this->conn = new \PDO($this->dsn, $this->username, $this->password, $this->connectionOptions);
            $this->conn->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
        }

        return $this->conn;
    }

    
SQL;
        $affectedShops = $this->conn->query($affectedShopsSql)->fetchAll();

        if (empty($affectedShops)) {
            return;
        }

        $sql = 'SELECT id FROM `s_core_templates` WHERE version = 3 AND parent_id IS NOT NULL ORDER BY id ASC LIMIT 1';
        $templateId = $this->conn->query($sql)->fetchColumn();

        foreach ($affectedShops as $shop) {
            if ($shop['tplId'] === null || $shop['tplVersion'] < 3) {
                $this->updateShopConfig('template_id', $templateId$shop['id']);
            }

            if ($shop['docTplId'] === null || $shop['docTplVersion'] < 3) {
                $this->updateShopConfig('document_template_id', $templateId$shop['id']);
            }
        }

        
Home | Imprint | This part of the site doesn't use cookies.