Connection.php 1.48 KB
Newer Older
romanb's avatar
romanb committed
1 2
<?php

Michael Moravec's avatar
Michael Moravec committed
3 4
declare(strict_types=1);

5 6
namespace Doctrine\DBAL\Driver;

7
use Doctrine\DBAL\DBALException;
8

romanb's avatar
romanb committed
9 10
/**
 * Connection interface.
11
 * Driver connections must implement this interface.
romanb's avatar
romanb committed
12
 *
13
 * This resembles (a subset of) the PDO interface.
romanb's avatar
romanb committed
14
 */
15
interface Connection
romanb's avatar
romanb committed
16
{
Benjamin Morel's avatar
Benjamin Morel committed
17 18 19
    /**
     * Prepares a statement for execution and returns a Statement object.
     */
20
    public function prepare(string $sql) : Statement;
Benjamin Morel's avatar
Benjamin Morel committed
21 22 23 24

    /**
     * Executes an SQL statement, returning a result set as a Statement object.
     *
25
     * @throws DBALException
Benjamin Morel's avatar
Benjamin Morel committed
26
     */
27
    public function query(string $sql) : ResultStatement;
Benjamin Morel's avatar
Benjamin Morel committed
28 29 30 31

    /**
     * Quotes a string for use in a query.
     */
32
    public function quote(string $input) : string;
Benjamin Morel's avatar
Benjamin Morel committed
33 34 35 36

    /**
     * Executes an SQL statement and return the number of affected rows.
     *
37
     * @throws DBALException
Benjamin Morel's avatar
Benjamin Morel committed
38
     */
39
    public function exec(string $statement) : int;
Benjamin Morel's avatar
Benjamin Morel committed
40 41 42 43 44 45 46 47

    /**
     * Returns the ID of the last inserted row or sequence value.
     *
     * @param string|null $name
     *
     * @return string
     */
48
    public function lastInsertId($name = null);
Benjamin Morel's avatar
Benjamin Morel committed
49 50 51 52

    /**
     * Initiates a transaction.
     *
53
     * @throws DriverException
Benjamin Morel's avatar
Benjamin Morel committed
54
     */
55
    public function beginTransaction() : void;
Benjamin Morel's avatar
Benjamin Morel committed
56 57 58 59

    /**
     * Commits a transaction.
     *
60
     * @throws DriverException
Benjamin Morel's avatar
Benjamin Morel committed
61
     */
62
    public function commit() : void;
Benjamin Morel's avatar
Benjamin Morel committed
63 64 65 66

    /**
     * Rolls back the current transaction, as initiated by beginTransaction().
     *
67
     * @throws DriverException
Benjamin Morel's avatar
Benjamin Morel committed
68
     */
69
    public function rollBack() : void;
Benjamin Eberlei's avatar
Benjamin Eberlei committed
70
}