bindValue example

foreach ($data as $key => $item) {
            // Determine the type string             if (is_int($item)) {
                $bindType = SQLITE3_INTEGER;
            } elseif (is_float($item)) {
                $bindType = SQLITE3_FLOAT;
            } else {
                $bindType = SQLITE3_TEXT;
            }

            // Bind it             $this->statement->bindValue($key + 1, $item$bindType);
        }

        $this->result = $this->statement->execute();

        return $this->result !== false;
    }

    /** * Returns the result object for the prepared query or false on failure. * * @return false|SQLite3Result */


        $sql = 'SELECT `name` FROM `s_core_config_mails` WHERE `name` = ( SELECT CONCAT("document_", `key`) FROM `s_core_documents` WHERE id=:documentTypeId )';
        $statement = $this->container->get(Connection::class)->prepare($sql);

        $statement->bindValue('documentTypeId', $documentTypeId, PDO::PARAM_INT);
        $result = $statement->executeQuery()->fetchAssociative();

        if (\is_array($result) && \array_key_exists('name', $result)) {
            $templateName = $result['name'];
        }

        return $templateName;
    }

    private function getCurrentLocale(): ?ShopLocale
    {
        
try {
            $stmt = $this->conn->prepare($sql);
        } catch (TableNotFoundException) {
            if (!$this->conn->isTransactionActive() || \in_array($platformName['pgsql', 'sqlite', 'sqlsrv'], true)) {
                $this->createTable();
            }
            $stmt = $this->conn->prepare($sql);
        }

        if ('sqlsrv' === $platformName || 'oci' === $platformName) {
            $bind = static function D$id$data) use ($stmt) {
                $stmt->bindValue(1, $id);
                $stmt->bindValue(2, $id);
                $stmt->bindValue(3, $data, ParameterType::LARGE_OBJECT);
                $stmt->bindValue(6, $data, ParameterType::LARGE_OBJECT);
            };
            $stmt->bindValue(4, $lifetime, ParameterType::INTEGER);
            $stmt->bindValue(5, $now, ParameterType::INTEGER);
            $stmt->bindValue(7, $lifetime, ParameterType::INTEGER);
            $stmt->bindValue(8, $now, ParameterType::INTEGER);
        } elseif (null !== $platformName) {
            $bind = static function D$id$data) use ($stmt) {
                $stmt->bindValue(1, $id);
                

    public function save(Key $key)
    {
        // prevent concurrency within the same connection         $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;
            }
public function bindParam($param, &$variable$type = ParameterType::STRING, $length = null): bool
    {
        $this->query->setParam($param$variable$type);

        return parent::bindParam($param$variable$type, ...\array_slice(\func_get_args(), 3));
    }

    public function bindValue($param$value$type = ParameterType::STRING): bool
    {
        $this->query->setValue($param$value$type);

        return parent::bindValue($param$value$type);
    }

    public function execute($params = null): ResultInterface
    {
        if (null !== $params) {
            $this->query->setValues($params);
        }

        // clone to prevent variables by reference to change         $this->debugDataHolder->addQuery($this->connectionName, $query = clone $this->query);

        
return true;
    }

    public function updateTimestamp(#[\SensitiveParameter] string $sessionId, string $data): bool     {
        $expiry = time() + (int) (($this->ttl instanceof \Closure ? ($this->ttl)() : $this->ttl) ?? \ini_get('session.gc_maxlifetime'));

        try {
            $updateStmt = $this->pdo->prepare(
                "UPDATE $this->table SET $this->lifetimeCol = :expiry, $this->timeCol = :time WHERE $this->idCol = :id"
            );
            $updateStmt->bindValue(':id', $sessionId, \PDO::PARAM_STR);
            $updateStmt->bindValue(':expiry', $expiry, \PDO::PARAM_INT);
            $updateStmt->bindValue(':time', time(), \PDO::PARAM_INT);
            $updateStmt->execute();
        } catch (\PDOException $e) {
            $this->rollback();

            throw $e;
        }

        return true;
    }

    
$stmt      = $this->conn->prepare($this->getInsertSQL());
        $tableName = $this->class->getTableName();

        foreach ($this->queuedInserts as $entity) {
            $insertData = $this->prepareInsertData($entity);

            if (isset($insertData[$tableName])) {
                $paramIndex = 1;

                foreach ($insertData[$tableName] as $column => $value) {
                    $stmt->bindValue($paramIndex++, $value$this->columnTypes[$column]);
                }
            }

            $stmt->executeStatement();

            if ($isPostInsertId) {
                $generatedId     = $idGenerator->generateId($this->em, $entity);
                $id              = [$this->class->identifier[0] => $generatedId];
                $postInsertIds[] = [
                    'generatedId' => $generatedId,
                    'entity' => $entity,
                ];
yield ['sqlite::memory:'];
    }

    protected function isPruned(PdoAdapter $cache, string $name): bool
    {
        $o = new \ReflectionObject($cache);

        $getPdoConn = $o->getMethod('getConnection');

        /** @var \PDOStatement $select */
        $select = $getPdoConn->invoke($cache)->prepare('SELECT 1 FROM cache_items WHERE item_id LIKE :id');
        $select->bindValue(':id', sprintf('%%%s', $name));
        $select->execute();

        return 1 !== (int) $select->fetch(\PDO::FETCH_COLUMN);
    }
}

    public function bindValue($parameter$value$type = null)
    {
        if (is_string($parameter) && $parameter[0] != ':') {
            $parameter = ":$parameter";
        }

        $this->_bindParam[$parameter] = $value;

        try {
            if ($type === null) {
                return $this->_stmt->bindValue($parameter$value);
            } else {
                return $this->_stmt->bindValue($parameter$value$type);
            }
        } catch (PDOException $e) {
            throw new Zend_Db_Statement_Exception($e->getMessage()$e->getCode()$e);
        }
    }

    /** * Closes the cursor, allowing the statement to be executed again. * * @return bool * @throws Zend_Db_Statement_Exception */
return true;
    }

    public function updateTimestamp(#[\SensitiveParameter] string $sessionId, string $data): bool     {
        $expiry = time() + (int) (($this->ttl instanceof \Closure ? ($this->ttl)() : $this->ttl) ?? \ini_get('session.gc_maxlifetime'));

        try {
            $updateStmt = $this->pdo->prepare(
                "UPDATE $this->table SET $this->lifetimeCol = :expiry, $this->timeCol = :time WHERE $this->idCol = :id"
            );
            $updateStmt->bindValue(':id', $sessionId, \PDO::PARAM_STR);
            $updateStmt->bindValue(':expiry', $expiry, \PDO::PARAM_INT);
            $updateStmt->bindValue(':time', time(), \PDO::PARAM_INT);
            $updateStmt->execute();
        } catch (\PDOException $e) {
            $this->rollback();

            throw $e;
        }

        return true;
    }

    

    public function testWithValueBound(callable $executeMethod)
    {
        $this->init();

        $sql = <<<EOT INSERT INTO products(name, price, stock, picture, tags, created_at) VALUES (?, ?, ?, ?, ?, ?) EOT;

        $stmt = $this->conn->prepare($sql);
        $stmt->bindValue(1, 'product1');
        $stmt->bindValue(2, 12.5);
        $stmt->bindValue(3, 5, ParameterType::INTEGER);
        $stmt->bindValue(4, $res = $this->getResourceFromString('mydata'), ParameterType::BINARY);
        $stmt->bindValue(5, ['foo', 'bar'], Types::SIMPLE_ARRAY);
        $stmt->bindValue(6, new \DateTimeImmutable('2022-06-12 11:00:00'), Types::DATETIME_IMMUTABLE);

        $executeMethod($stmt);

        $debug = $this->debugDataHolder->getData()['default'] ?? [];
        $this->assertCount(2, $debug);
        $this->assertSame($sql$debug[1]['sql']);
        
if ($mergeStmt !== null) {
                $mergeStmt->execute();

                return true;
            }

            $updateStmt = $this->pdo->prepare(
                "UPDATE $this->table SET $this->dataCol = :data, $this->expiryCol = :expiry, $this->timeCol = :time WHERE $this->idCol = :id"
            );
            $updateStmt->bindParam(':id', $sessionId, PDO::PARAM_STR);
            $updateStmt->bindParam(':data', $data, PDO::PARAM_LOB);
            $updateStmt->bindValue(':expiry', time() + $maxlifetime, PDO::PARAM_INT);
            $updateStmt->bindValue(':time', time(), PDO::PARAM_INT);
            $updateStmt->execute();

            // When MERGE is not supported, like in Postgres < 9.5, we have to use this approach that can result in             // duplicate key errors when the same session is written simultaneously (given the LOCK_NONE behavior).             // We can just catch such an error and re-execute the update. This is similar to a serializable             // transaction with retry logic on serialization failures but without the overhead and without possible             // false positives due to longer gap locking.             if (!$updateStmt->rowCount()) {
                try {
                    $insertStmt = $this->pdo->prepare(
                        "


    protected function tearDown(): void
    {
        $this->removeAddedDefaultDomains();
        $this->removeAddedSalesChannel();
    }

    public function testItAddsDefaultDomainToHeadlessSalesChannel(): void
    {
        $statement = $this->connection->prepare('SELECT COUNT(*) FROM `sales_channel_domain` WHERE `sales_channel_id` = :salesChannelId');
        $statement->bindValue('salesChannelId', Uuid::fromHexToBytes(TestDefaults::SALES_CHANNEL));

        $result = $statement->executeQuery();
        static::assertEquals(0, $result->fetchOne());

        (new Migration1620820321AddDefaultDomainForHeadlessSaleschannel())->update($this->connection);

        $result = $statement->executeQuery();
        static::assertEquals(1, $result->fetchOne());
    }

    public function testItAddsDefaultDomainToMultipleApiSalesChannel(): void
    {
public function save($data)
    {
        if ($this->mysql === null)
        {
            return false;
        }

        $query = $this->mysql->prepare('DELETE i, cd FROM `' . $this->options['extras']['prefix'] . 'cache_data` cd, ' .
            '`' . $this->options['extras']['prefix'] . 'items` i ' .
            'WHERE cd.id = i.feed_id ' .
            'AND cd.mtime < (unix_timestamp() - :purge_time)');
        $query->bindValue(':purge_time', $this->options['extras']['cache_purge_time']);

        if (!$query->execute())
        {
            return false;
        }

        if ($data instanceof SimplePie)
        {
            $data = clone $data;

            $prepared = self::prepare_simplepie_object_for_cache($data);

            
$sql = "INSERT INTO $this->table ($this->idCol, $this->tokenCol, $this->expirationCol) VALUES (:id, :token, {$this->getCurrentTimestampStatement()} + $this->initialTtl)";
        $conn = $this->getConnection();
        try {
            $stmt = $conn->prepare($sql);
        } catch (\PDOException) {
            if (!$conn->inTransaction() || \in_array($this->driver, ['pgsql', 'sqlite', 'sqlsrv'], true)) {
                $this->createTable();
            }
            $stmt = $conn->prepare($sql);
        }

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

        try {
            $stmt->execute();
        } catch (\PDOException) {
            // the lock is already acquired. It could be us. Let's try to put off.             $this->putOffExpiration($key$this->initialTtl);
        }

        $this->randomlyPrune();
        $this->checkNotExpired($key);
    }
Home | Imprint | This part of the site doesn't use cookies.