src/Expression.php
public function execute($connection = null)
    {
        if ($connection === null) {
            $connection = $this->connection;
        }

        // If it's a PDO connection, we're cool
        if ($connection instanceof \PDO) {
            $connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
            // We support PDO
            $query = $this->render();
            $statement = $connection->prepare($query);
            foreach ($this->params as $key => $val) {
                if (is_int($val)) {
                    $type = \PDO::PARAM_INT;
                } elseif (is_bool($val)) {
                    // SQL does not like booleans at all, so convert them INT
                    $type = \PDO::PARAM_INT;
                    $val = (int) $val;
                } elseif ($val === null) {
                    $type = \PDO::PARAM_NULL;
                } elseif (is_string($val) || is_float($val)) {
                    $type = \PDO::PARAM_STR;
                } elseif (is_resource($val)) {
                    $type = \PDO::PARAM_LOB;
                } else {
                    throw new Exception([
                        'Incorrect param type',
                        'key'   => $key,
                        'value' => $val,
                        'type'  => gettype($val),
                    ]);
                }

                // Workaround to support LOB data type. See https://github.com/doctrine/dbal/pull/2434
                $this->boundValues[$key] = $val;
                if ($type === \PDO::PARAM_STR) {
                    $bind = $statement->bindParam($key, $this->boundValues[$key], $type, strlen($val));
                } else {
                    $bind = $statement->bindParam($key, $this->boundValues[$key], $type);
                }

                if (!$bind) {
                    throw new Exception([
                        'Unable to bind parameter',
                        'param' => $key,
                        'value' => $val,
                        'type'  => $type,
                    ]);
                }
            }

            $statement->setFetchMode(\PDO::FETCH_ASSOC);

            try {
                $statement->execute();
            } catch (\Exception $e) {
                $new = new Exception([
                    'DSQL got Exception when executing this query',
                    'error' => $e->getMessage(),
                    'query' => $this->getDebugQuery(),
                ]);
                $new->by_exception = $e;

                throw $new;
            }

            return $statement;
        } else {
            return $connection->execute($this);
        }
    }
public function execute($connection = null)
    {
        if ($connection === null) {
            $connection = $this->connection;
        }

        // If it's a PDO connection, we're cool
        if ($connection instanceof \PDO) {
            $connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
            // We support PDO
            $query = $this->render();
            $statement = $connection->prepare($query);
            foreach ($this->params as $key => $val) {
                if (is_int($val)) {
                    $type = \PDO::PARAM_INT;
                } elseif (is_bool($val)) {
                    // SQL does not like booleans at all, so convert them INT
                    $type = \PDO::PARAM_INT;
                    $val = (int) $val;
                } elseif ($val === null) {
                    $type = \PDO::PARAM_NULL;
                } elseif (is_string($val) || is_float($val)) {
                    $type = \PDO::PARAM_STR;
                } elseif (is_resource($val)) {
                    $type = \PDO::PARAM_LOB;
                } else {
                    throw new Exception([
                        'Incorrect param type',
                        'key'   => $key,
                        'value' => $val,
                        'type'  => gettype($val),
                    ]);
                }

                // Workaround to support LOB data type. See https://github.com/doctrine/dbal/pull/2434
                $this->boundValues[$key] = $val;
                if ($type === \PDO::PARAM_STR) {
                    $bind = $statement->bindParam($key, $this->boundValues[$key], $type, strlen($val));
                } else {
                    $bind = $statement->bindParam($key, $this->boundValues[$key], $type);
                }

                if (!$bind) {
                    throw new Exception([
                        'Unable to bind parameter',
                        'param' => $key,
                        'value' => $val,
                        'type'  => $type,
                    ]);
                }
            }

            $statement->setFetchMode(\PDO::FETCH_ASSOC);

            try {
                $statement->execute();
            } catch (\Exception $e) {
                $new = new Exception([
                    'DSQL got Exception when executing this query',
                    'error' => $e->getMessage(),
                    'query' => $this->getDebugQuery(),
                ]);
                $new->by_exception = $e;

                throw $new;
            }

            return $statement;
        } else {
            return $connection->execute($this);
        }
    }
Execute expression.

@param \PDO|Connection $connection

@return \PDOStatement