Doctrine\DBAL\Connection::convertToDatabaseValue PHP Method

convertToDatabaseValue() public method

Converts a given value to its database representation according to the conversion rules of a specific DBAL mapping type.
public convertToDatabaseValue ( mixed $value, string $type ) : mixed
$value mixed The value to convert.
$type string The name of the DBAL mapping type.
return mixed The converted value.
    public function convertToDatabaseValue($value, $type)
    {
        return Type::getType($type)->convertToDatabaseValue($value, $this->getDatabasePlatform());
    }

Usage Example

コード例 #1
0
 /**
  * {@inheritdoc}
  */
 public function execute(LoggerInterface $logger)
 {
     // update field itself
     $sql = "UPDATE oro_entity_config_index_value\n            SET value = ?\n            WHERE\n                entity_id = (SELECT id FROM oro_entity_config WHERE class_name = ? LIMIT 1) AND\n                field_id IS NULL AND\n                scope = ? AND\n                code = ?\n            ";
     $parameters = [$this->value, $this->entityName, $this->scope, $this->code];
     $statement = $this->connection->prepare($sql);
     $statement->execute($parameters);
     $this->logQuery($logger, $sql, $parameters);
     $logger->debug($sql);
     // update entity config cached data
     $sql = 'SELECT data FROM oro_entity_config WHERE class_name = ? LIMIT 1';
     $parameters = [$this->entityName];
     $data = $this->connection->fetchColumn($sql, $parameters);
     $this->logQuery($logger, $sql, $parameters);
     $data = $data ? $this->connection->convertToPHPValue($data, Type::TARRAY) : [];
     $data[$this->scope][$this->code] = $this->value;
     $data = $this->connection->convertToDatabaseValue($data, Type::TARRAY);
     $sql = 'UPDATE oro_entity_config SET data = ? WHERE class_name = ?';
     $parameters = [$data, $this->entityName];
     $statement = $this->connection->prepare($sql);
     $statement->execute($parameters);
     $this->logQuery($logger, $sql, $parameters);
 }