mixed adoNewConnection( optional string $driverType='' )
The function adoNewConnection, in the simple form, loads the database driver specific files as specified by the string $driverType
. The driver name must match the name of a file adodb-$driverType-inc.php
in the adodb/drivers
directory. As there is no 'master list' of drivers, the driver can be named anything, it's existence in this directory is the only way of checking it's validity. This simplicity makes it easy to create a new driver.
In addition to the simple form, a DSN connection string can be passed to any database that supports that connection type. The $driverType
string must be in the following format:
"valid driver name" + "://" + "standard DSN string"
If the DSN string parses correctly, an attempt is made to automatically connect to the database. If the connection succeeds, then there is no need to issue a connect() statement.
include 'adodb.inc.php'; /* * Simple connection */ $driver = 'mysqli'; $db = adoNewConnection($driver); /* * Now connect to the database */ $db->connect('localhost','user','password','employees');
include 'adodb.inc.php'; /* * Set DSN */ $driver = 'mysqli'; $DSN = "user:password@localhost/employees"; $db = adoNewConnection($driver . '://' . $DSN); /* * Now connected */
The following additional parameter can be added to the DSN connection string. Some of the parameters only work with specific drivers.
Code | Driver | Value | Parameter | Description |
---|---|---|---|---|
new | true | nConnect() | Forces a new connection | |
persist | true | pConnect() | Creates a persistent connection | |
persistent | true | pConnect() | Creates a persistent connection | |
debug | true | debug | Enables debug mode | |
port | mysqli, postgres9 | int | Sets the connection port | |
socket | mysqli | string | Sets the connection socket | |
nls_date_format | oci8 | string | Set date format | |
cachesecs | int | Sets the number of cache seconds | ||
memCache | false | memcache | Enables memcache library for caching | |
memCacheHost | array | memcache | Array of one or more memcached servers | |
memCachePort | int | memcache | Optional alternative port to connect to memcache server(s) | |
memCacheCompress | false | memcache | Enables memcache compression (not supported with memcached library) |
Note that, because no connection object is available, the codes cannot be retrieved via errorMsg()