1Horde_Db
2
3Horde_Db provides database connection abstraction and SQL compatibility tools for a number of database systems and PHP extensions. It currently supports the following databases and extensions:
4
5+-------------+----------+
6|Database     |Extension |
7+-------------+----------+
8|MySQL/MariaDB|mysql     |
9|             +----------+
10|             |mysqli    |
11|             +----------+
12|             |PDO_mysql |
13+-------------+----------+
14|PostgreSQL   |PDO_pgsql |
15+-------------+----------+
16|SQLite       |PDO_sqlite|
17+-------------+----------+
18|Oracle       |oci8      |
19+-------------+----------+
20
21Advanced features include:
22
23- Connection abstraction
24- SQL compatibility tools
25- Database schema management
26- Master/server configuration with queries split to write and read instances
27- BLOB/CLOB handling
28- Caching
29- Query logging
30
31Connection management
32
33Connecting to a database is as simple as instantiating a class implementing the Horde_Db_Adapter interface, providing the necessary connection parameters:
34
35MySQL
36
37Please note that the mysql PHP extension is deprecated as of PHP 7, as is the Horde_Db_Adapter_Mysql backend.
38
39$config = [
40    'host'     => 'localhost',
41    'username' => 'user',
42    'password' => 'secret',
43    'database' => 'db',
44];
45$db = new Horde_Db_Adapter_Mysqli($config);
46$db = new Horde_Db_Adapter_Pdo_Mysql($config);
47$db = new Horde_Db_Adapter_Mysql($config);
48
49Full list of connection parameters:
50
51+---------------+---------+--------------------------------------+
52|Parameter      |Mandatory|Meaning                               |
53+---------------+---------+--------------------------------------+
54|charset        |         |Connection character set              |
55+---------------+---------+--------------------------------------+
56|database/dbname|         |Database name                         |
57+---------------+---------+--------------------------------------+
58|host           |         |Host name, if using TCP connection (1)|
59+---------------+---------+--------------------------------------+
60|port           |         |Port number, if using TCP connection  |
61+---------------+---------+--------------------------------------+
62|socket         |         |Socket location, if using Unix sockets|
63+---------------+---------+--------------------------------------+
64|username       |X        |Database user                         |
65+---------------+---------+--------------------------------------+
66
67.:1 To workaround MySQL automatically using the unix socket if setting the host to 'localhost', the hostname will be translated from 'localhost' to '127.0.0.1' if using the TCP protocol
68