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

3 4
namespace Doctrine\DBAL\Driver;

5
use Doctrine\DBAL\DBALException;
6 7
use Doctrine\DBAL\ParameterType;

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

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

    /**
     * Quotes a string for use in a query.
     *
31 32
     * @param mixed $input
     * @param int   $type
Benjamin Morel's avatar
Benjamin Morel committed
33
     *
34
     * @return mixed
Benjamin Morel's avatar
Benjamin Morel committed
35
     */
36
    public function quote($input, $type = ParameterType::STRING);
Benjamin Morel's avatar
Benjamin Morel committed
37 38 39 40

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

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

    /**
     * Initiates a transaction.
     *
57
     * @return bool TRUE on success or FALSE on failure.
Benjamin Morel's avatar
Benjamin Morel committed
58
     */
59
    public function beginTransaction();
Benjamin Morel's avatar
Benjamin Morel committed
60 61 62 63

    /**
     * Commits a transaction.
     *
64
     * @return bool TRUE on success or FALSE on failure.
Benjamin Morel's avatar
Benjamin Morel committed
65
     */
66
    public function commit();
Benjamin Morel's avatar
Benjamin Morel committed
67 68 69 70

    /**
     * Rolls back the current transaction, as initiated by beginTransaction().
     *
71
     * @return bool TRUE on success or FALSE on failure.
Benjamin Morel's avatar
Benjamin Morel committed
72
     */
73
    public function rollBack();
Benjamin Morel's avatar
Benjamin Morel committed
74 75 76 77 78 79

    /**
     * Returns the error code associated with the last operation on the database handle.
     *
     * @return string|null The error code, or null if no operation has been run on the database handle.
     */
80
    public function errorCode();
Benjamin Morel's avatar
Benjamin Morel committed
81 82 83 84

    /**
     * Returns extended error information associated with the last operation on the database handle.
     *
85
     * @return mixed[]
Benjamin Morel's avatar
Benjamin Morel committed
86
     */
87
    public function errorInfo();
Benjamin Eberlei's avatar
Benjamin Eberlei committed
88
}